更新
事实证明这是由于无法在远程桌面连接上生成光栅图形的问题。
我已经尝试了不同的xy值以及多种不同的图像格式,但都没有成功。
我的问题在于使用rastergrob对象与annotate_custom()一起使用时出现问题,因为ggplot2文档站点上关于annotate_custom()的示例可以正常工作,例如:
我正在使用64位Windows上的R版本3.0.2,ggplot2版本为0.9.3.1,并且我的软件包都已更新。
如果我错过了一些简单的东西,请告诉我您的想法。感谢您的帮助!
我想在使用ggplot2绘制的图表中插入一个来自文件的图片。这个问题已经在这里被问过了(Inserting an image to ggplot2),但是对于我而言,被接受的答案会产生一个没有任何图像的图表(导出的图表;我无法在这里上传图片)。以下是代码:
library(ggplot2)
library(png)
library(grid)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
g <- rasterGrob(img, interpolate=TRUE)
qplot(1:10, 1:10, geom="blank") +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point()
我已经尝试了不同的xy值以及多种不同的图像格式,但都没有成功。
我的问题在于使用rastergrob对象与annotate_custom()一起使用时出现问题,因为ggplot2文档站点上关于annotate_custom()的示例可以正常工作,例如:
library(gridExtra)
qplot(1:10, 1:10, geom = "blank") +
annotation_custom(grob = tableGrob(head(iris[ ,1:3])),
xmin = 3, xmax = 6, ymin = 2, ymax = 8)
我正在使用64位Windows上的R版本3.0.2,ggplot2版本为0.9.3.1,并且我的软件包都已更新。
如果我错过了一些简单的东西,请告诉我您的想法。感谢您的帮助!