将自定义图像显示为geom_point

赛斯

是否可以在R ggplot中将自定义图像(例如png格式)显示为geom_point?

library(png)
pic1 <- readPNG("pic1.png")

png("Heatmap.png", units="px", width=3200, height=3200, res=300)
ggplot(data_frame, aes(medium, day, fill = Transactions))  +
   geom_tile(colour="white")  +
   facet_grid(dime3_year~dime3_month) + 
   scale_fill_gradient(high="blue",low="white") +
   theme_bw() + 
   geom_point(aes(dime3_channel, day, size=Conv,alpha=Conv,image=(annotation_raster(pic1,xmin=0,ymin=0,xmax=5,ymax=5)),color="firebrick")) +

给出错误:

不知道如何为原型/环境类型的对象自动选择比例。默认为连续错误:美学必须为长度1或与数据长度相同问题:(annotation_raster(conv_pic,xmin = 0,ymin = 0,xmax = 5,ymax = 5))

2015年

点几何用于创建散点图,并且似乎并不能完全按照您的需要进行设计,即显示自定义图像。但是,这里回答了类似的问题,表明可以通过以下步骤解决该问题:

(1)阅读要显示的自定义图像,

(2)使用rasterGrob()函数在给定的位置,大小和方向上渲染栅格对象

(3)使用一个绘图功能,例如qplot()

(4)使用诸如annotation_custom()静态注释之类的geom来指定用户20650提到的x和y极限的粗略调整。

使用下面的代码,我可以在给定的xmin,xmax,ymin和ymax处获得两个自定义图像img1.png和img2.png。

library(png)
library(ggplot2)
library(gridGraphics)
setwd("c:/MyFolder/")

img1 <- readPNG("img1.png")
img2 <- readPNG("img2.png")
g1 <- rasterGrob(img1, interpolate=FALSE)
g2 <- rasterGrob(img2, interpolate=FALSE)
qplot(1:10, 1:10, geom="blank") + 
  annotation_custom(g1, xmin=1, xmax=3, ymin=1, ymax=3) +
  annotation_custom(g2, xmin=7, xmax=9, ymin=7, ymax=9) +  
  geom_point()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章