【发布时间】:2021-10-30 10:30:27
【问题描述】:
我有一个使用 st_read() 从 shapefile 导入的轮廓数据集。我使用ggplot() 和geom_sf() 绘制了这个图。它渲染得很好。现在我想标记轮廓。使用geom_st_label() 不会产生很好的输出。轮廓处处密集,标签重叠。
我查看了metR 包。这有一个geom_contour_label() 函数,可以很好地控制ggplot() 中的轮廓放置。但是,geom_contour() 和相关函数无法识别 sf_objects 中包含的几何图形。我收到此错误:stat_contour requires the following missing aesthetics: x, y and z。
如何让geom_contour_label() 使用 sf 对象?这是geom_contour_label() 可以产生的:
我的轮廓数据可从https://cloudstor.aarnet.edu.au/sender/?s=download&token=241de91b-2015-4a19-a18f-c2125a12f2a7获得。
library(sf)
library(tidyverse)
isobath <- read_sf("1misobath.shp")
ggplot() +
geom_sf(data = isobath, color = "blue", lwd = 0.25) +
geom_sf_label(data = isobath, aes(label = DEPTH), size = 2) +
coord_sf(xlim = c(18.42, 18.5), ylim = c(-34.20, -34.16), expand = T) +
theme_bw()
【问题讨论】:
-
嗨@aterhorst。不知道我是否可以帮助你,但目前我无法下载文件;-)
-
固定下载链接。
-
我查看了
st_coordinates(),可以提取 XY 坐标以及相应的线串标识符。为什么geom_contour()无法处理 sf 对象令人费解。 -
感谢您的链接。明天我会详细研究这个(目前,在法国已经很晚了,我的神经元断开了!!)。干杯。
-
嗨@aterhorst。经过几个小时的彻底检查/测试,我认为我已经找到了解决您的映射问题的令人满意的解决方案(参见下面的答案)。我希望它会满足你的愿望。干杯。