hea*_*rse 2 plot r image scatter-plot cran
给定png/jpeg格式的'n'图像和2维(x,y)的'n'对应坐标:我想在单个图上的给定坐标处绘制这些图像.如果我发现图像太大,我最好将它们绘制为给定坐标处的较小/缩放版本.我怎样才能在R中实现这样的情节?
下面给出了这种情节如何看的一个例子:

xy <- data.frame(x=runif(10, 0, 100), y=runif(10, 0, 100))
require(png)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
thumbnails <- function(x, y, images, width = 0.1*diff(range(x)),
height = 0.1*diff(range(y))){
images <- replicate(length(x), images, simplify=FALSE)
stopifnot(length(x) == length(y))
for (ii in seq_along(x)){
rasterImage(images[[ii]], xleft=x[ii] - 0.5*width,
ybottom= y[ii] - 0.5*height,
xright=x[ii] + 0.5*width,
ytop= y[ii] + 0.5*height, interpolate=FALSE)
}
}
plot(xy, t="n")
thumbnails(xy[,1], xy[,2], img)
Run Code Online (Sandbox Code Playgroud)
