有没有办法将图像插入到 R 的绘图中并在这样做时设置其颜色?我想为给定的数据集插入轮廓,并将其设置为与我选择用于绘制相应数据点的颜色相匹配。我对一般计算机系统和 R 中的图形管理方式没有深入的了解,这可能会告诉您这个问题的答案。
下面的代码将插入图像,但我无法找到更改颜色的方法。
require(jpeg)
thiscolor <- "red"
plot(x=c(1, 4), y=c(1, 2), main="test plot", col=thiscolor)
thispic <- readJPEG(<insert path for any image here>)
rasterImage(thispic,
xleft=3, xright=3.5,
ytop=2, ybottom=1.8,
)
我不明白你所说的剪影到底是什么意思。但对我来说,光栅是颜色矩阵。所以你可以改变它的颜色。这里有一个演示。我在用,grid.raster
来自grid
包裹。但这与rasterImage
这是一个例子:
library(png)
library(grid)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
## convert it to a raster, interpolate =F to select only sample of pixels of img
img.r <- as.raster(img,interpolate=F)
## Change all the white to a blanck
img.r[img.r == "#00000000"] <- 'red'
plot.new()
grid.raster(img.r)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)