[英]How to smooth a plot produced with image function in R?
I'm producing an elevation map with R base function "image". 我正在制作一个带有R基函数“image”的高程图。 Nonetheless, I'd like to get a smoother transition between levels so the image looks less pixelated. 尽管如此,我希望在各级之间获得更平滑的过渡,以使图像看起来像素化更少。 The logical solution is adding a wider color palette, which I already did, but the result isn't satisfactory yet. 逻辑解决方案是添加更宽的调色板,我已经做过,但结果还不令人满意。 How can I achieve a nice smoothing effect without altering the coordinate system (I need it to overlay a series of segments and points)? 如何在不改变坐标系的情况下实现良好的平滑效果(我需要覆盖一系列的段和点)?
x <- 10*(1:nrow(volcano))
y <- 10*(1:ncol(volcano))
shades = colorRampPalette(c("yellow", "red"))
image(x, y, volcano,
col=shades(100),breaks=seq(min(volcano),max(volcano),
(max(volcano)- min(volcano))/100),axes = FALSE)
segments(x0=c(100,600), x1=c(600,100),
y0=c(100,600),
y1=c(600,100))
points(x=seq(100,800,100), y=rep(300,8),pch=16,col="blue",cex=3)
axis(1, at = seq(100, 800, by = 100))
axis(2, at = seq(100, 600, by = 100))
For some reason interpolate=FALSE
is hard-coded in image.default
, but you can use the lower-level rasterImage
function directly: 出于某种原因, image.default
interpolate=FALSE
在image.default
是硬编码的,但您可以直接使用较低级别的rasterImage
函数:
m <- cut(scales::rescale(volcano), 100)
levels(m) <- shades(100)
m <- as.character(m)
dim(m) <- dim(volcano)
m <- t(m)[ncol(m):1,]
rasterImage(as.raster(m), min(x), min(y), max(x), max(y), interpolate = TRUE)
Side-by-side comparison: 并排比较:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.