如何找到轮廓图并以90个百分点突出显示?

发布于 2025-01-19 01:06:19 字数 493 浏览 0 评论 0原文

我有一个光栅图像,其值范围为 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)

我得到了这种类型的图像,但我想要带有阴影的图像(右侧)。非常感谢您帮助制作这张照片。

输入图片此处描述

I have a raster image whose value ranges from 1 to 10.
I want to find the 90 percentile of mine raster data. And need to find the contour graph by highlighting the area having the 90 percentile. I want a figure for my raster data is attached below. I am doing my analysis in R.

   library(raster)
   library(cartography)
   library(sf)
   library(SpatialPosition)

   r <- raster("E:/data.tif", package="raster")
   plot(r)
   contour(r, add=TRUE)

I got this type of image, but I wants the one with a shaded one (right side). Help on making this picture will be much appreciated.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱着落日 2025-01-26 01:06:19

显然,没有您的数据,但是我们可以制作这样的示例栅格:

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") 

”在此处输入图像描述”

Obviously, don't have your data, but we can make an example raster like this:

r <- raster(t(volcano[,ncol(volcano):1]))

From now on, the following code should work with your own raster too. We can get the 90th centile of our data like this:

centile90 <- quantile(r[], 0.9)

Now let's convert the raster to an x, y, z data frame:

df <- as.data.frame(as(r, "SpatialPixelsDataFrame"))
colnames(df) <- c("value", "x", "y")

We can use the feature-rich ggplot2 library for drawing the data. We will plot as a filled contour map and add a bright green contour at our 90th centile:

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") 

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文