我有一个光栅图像,其值从1到10。我想找到我的栅格数据的90百分位数。并需要通过高亮显示有90个百分位数的区域来找到等高线图。我想要我的光栅数据的数字附在下面。我正在R.
library(raster)
library(cartography)
library(sf)
library(SpatialPosition)
r <- raster("E:/data.tif", package="raster")
plot(r)
contour(r, add=TRUE)我得到了这种类型的图像,但我想要一个阴影的(右侧)。帮助制作这张照片将是非常感谢的。

发布于 2022-04-03 15:55:59
显然,没有您的数据,但我们可以这样做一个例子光栅:
r <- raster(t(volcano[,ncol(volcano):1]))从现在开始,下面的代码也应该与您自己的光栅一起工作。我们可以得到数据的90厘米如下:
centile90 <- quantile(r[], 0.9)现在,让我们将光栅转换为x,y,z数据帧:
df <- as.data.frame(as(r, "SpatialPixelsDataFrame"))
colnames(df) <- c("value", "x", "y")我们可以使用功能丰富的ggplot2库来绘制数据。我们将绘制成一个填充的等高线图,并在90厘米处添加一个明亮的绿色轮廓:
library(ggplot2)
ggplot(df, aes(x, y, z = value)) +
geom_contour_filled(bins = 10) +
geom_contour(breaks = centile90, colour = "green",
size = 2) +
scale_fill_manual(values = hcl.colors(10, "YlOrRd", rev = TRUE)) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
theme_classic() +
theme(legend.position = "none")

https://stackoverflow.com/questions/71727088
复制相似问题