【发布时间】:2017-07-05 05:09:18
【问题描述】:
我想为每个方面添加一个自定义图像。使用 annotation_custom 在所有方面复制图像,例如:
require(ggplot2); require(grid); require(png); require(RCurl)
p = ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_wrap(~Species)
img1 = readPNG(getURLContent('https://cdn2.iconfinder.com/data/icons/animals/48/Turtle.png'))
img2 = readPNG(getURLContent('https://cdn2.iconfinder.com/data/icons/animals/48/Elephant.png'))
img3 = readPNG(getURLContent('https://cdn2.iconfinder.com/data/icons/animals/48/Hippopotamus.png'))
a1 = annotation_custom(rasterGrob(img1, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5)
a2 = annotation_custom(rasterGrob(img2, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5)
a3 = annotation_custom(rasterGrob(img3, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5)
p + a1
是否有替代方法来实现这一点,以便img1-3 正确填充各个方面?
【问题讨论】:
-
您可以使用 @baptiste 的 annotation_custom2 函数。见stackoverflow.com/questions/32807665/…
-
@baptiste 的巧妙破解。感谢您的链接。想记下答案吗?我的电话是
a1 = annotation_custom2(rasterGrob(img1, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5, data=iris[1,])