我想用下面的代码创建一个热图。
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...也就是说,热图的某些部分落在下图所示的poygon内。enter image description here
有什么想法吗?
发布于 2021-11-10 12:49:33
看起来这个线程做了类似的事情ggplot2/gis Plotting inside polygon area我以前也做过类似的事情,使用sf包中的st_intersection(),在绘制之前过滤与多边形重叠的数据。
https://stackoverflow.com/questions/69912330
复制相似问题