用户在r中拥有pch(剪辑)

jon*_*jon 11 plot r pch ggplot2

可能重复:
如何将图像用作ggplot中的一个点?

是否可以将用户定义的pch(剪贴画或图标或其他类型的文件)用作R base或ggplot或其他图形设备中的点.

例如:

在此输入图像描述

set.seed(123)
mydt <- data.frame (x = rnorm(5, 5,2), y = rnorm (5,10,3), z = rnorm (5, 1,0.5))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这里的大小与z成正比.

ags*_*udy 16

运用 grid.raster

library(png)
flower <- readPNG("flower.png")
pushViewport(plotViewport(margins=c(5,5,5,5)))
grid.rect(gp = gpar(fill=NA))
pushViewport(plotViewport(margins=c(5,5,5,5),
                          xscale=extendrange(mydt$x),
                          yscale=extendrange(mydt$y)))


grid.raster(image=flower,x=mydt$x,y=mydt$y,width=mydt$z, 
                interpolate=FALSE,default.units = 'native')
grid.polyline(mydt$x,mydt$y,default.units='native')
upViewport(2)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述