【问题标题】:R density map over a specific multipolygon特定多面体上的 R 密度图
【发布时间】:2021-12-22 23:54:51
【问题描述】:

我想用下面的代码创建一个热图。

data_smoothed = ggplot() +
  metR::geom_contour_fill(data = data.dolphins, aes(x = lon, y = lat, z = density), 
                          bins = 120, na.fill = TRUE)+
  coord_sf(xlim = c(-1, 5), ylim = c(37,43))+ #I want to change this 
  scale_fill_viridis_c() +
  metR::scale_x_longitude(ticks = 2)+
  metR::scale_y_latitude(ticks=2)+
  theme_bw() +
  ggtitle("dolphins")+
  theme(plot.title = element_text(hjust = 0.5)) 

返回这个: enter image description here

但是,我不想收到这个,我只想保留热图的这些部分,这些部分属于我已经拥有的多面体。

> poly
Simple feature collection with 1 feature and 0 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -1 ymin: 37 xmax: 6 ymax: 42.42764
Geodetic CRS:  WGS 84
                        geometry
1 MULTIPOLYGON (((0.5 39.5, 0...

即类似于下面显示的多边形内的热图部分。 enter image description here

有什么想法吗?

【问题讨论】:

    标签: r ggplot2 heatmap kernel-density


    【解决方案1】:

    似乎这个线程做了类似的事情ggplot2/gis Plotting inside polygon area 我过去也使用 sf 包中的 st_intersection() 做过类似的事情,在绘图之前过滤与多边形重叠的数据。

    【讨论】:

    • 我以前看过这篇文章。我的数据点实际上在多面体中。所以我认为这更多的是插值问题或如何呈现数据。
    • 我明白了,只需在数据之上绘制多边形就可以实现您想要的外观吗?我不确定我明白你想要什么:)
    • 不,我只想对多边形内的区域进行着色。感谢您的帮助:)
    猜你喜欢
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 2021-05-25
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多