r - 特定多面体上的 R 密度图
问题描述
我想用下面的代码创建一个热图。
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))
它返回这个: 在此处输入图像描述
但是,我不想收到这个,我只想保留热图的这些部分,这些部分属于我已经拥有的多面体。
> 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...
即类似于下面显示的多边形内的热图部分。 在此处输入图像描述
有任何想法吗?
解决方案
似乎这个线程在多边形区域内做了类似的 ggplot2/gis 绘图 我过去也使用 sf 包中的 st_intersection() 做过类似的事情,在绘图之前过滤与多边形重叠的数据。
推荐阅读
- git - 给定缩小文件,如何找到 D3 的确切版本?
- apache-spark - 读取带有模式的 JSON 数组字符串返回 null spark 2.2.0
- javascript - 在迭代数组咖啡脚本时检查未定义
- python - 一周前工作的代码,现在我得到一个错误,而没有更改我的代码中的任何内容
- neo4j - 在 neo4j 中创建节点之间的关系非常慢
- android - 在 react native 中使用倒置的 FlatList 时滚动无法正常工作
- php - 使用 file_get_contents 保留缩进
- android - 为相机意图创建 URI 时应用程序崩溃
- android - 适用于 Android 的 Fabric 插件中的每日新用户身份 - crashlytics
- java - 没有模块化的 Java 11:包在作为 maven 依赖项添加时不存在