首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >特定多多边形上的R密度贴图

特定多多边形上的R密度贴图
EN

Stack Overflow用户
提问于 2021-11-10 11:16:07
回答 1查看 33关注 0票数 0

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

代码语言:javascript
复制
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

然而,我只想将热图的这些部分保留在我已经拥有的多面体中,而不是接收到这个。

代码语言:javascript
复制
> 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...

也就是说,热图的某些部分落在下图所示的poygon内。enter image description here

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2021-11-10 12:49:33

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69912330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档