我在我的情节上获得指北针和比例尺时遇到问题。
我使用 ggmap 构建了绘图,并且正在使用 ggsn 包来获取指北针/比例尺,但出现以下错误:
“坐标系已经存在。添加新的坐标系,它将替换现有的坐标系。ggsn::scalebar 中的错误(x.min = -160, x.max = 135, y.min = 15, y.max = 70, :转换应该是合乎逻辑的。”
这是我的绘图的可重现代码和上面详述的错误:
bbox <- c(left = -160, bottom = 15, right = 135, top = 70)
latitude = c(49.38639, 50.68870, 50.77530, 49.86880, 39.31181, 37.05229)
longitude = c(-121.45063, -120.36646, 50, -97.40836, 76.71748, -119.19536)
site_df = as.data.frame(cbind(latitude,longitude))
site_map = ggmap(get_stamenmap(bbox, maptype = "terrain-background", zoom = 2))+
geom_point(data = site_df, aes(x = longitude, y = latitude),
size = 1.5, color = "orange")+
geom_point(data = site_df, aes(x = longitude, y = latitude),
pch= 21, size = 2, color = "black")+
theme_bw() +
labs(x = "Longitude", y = "Latitude")
site_map +
coord_equal() + # needed for ggsn
guides(alpha=FALSE, size=FALSE) +
ggsn::north(x.min = -160, x.max = 135,
y.min = 15, y.max = 70, scale = 0.2) +
ggsn::scalebar(x.min = -160, x.max = 135,
y.min = 15, y.max = 70,
dist = 5, dd2km = TRUE,
model = "WGS84", height = 0.5,
st.dist = 0.5)
我也试过
site_map +
geom_sf(data = site_df, aes(x = longitude, y = latitude)) +
annotation_scale(location = "bl", width_hint = 0.125) +
annotation_north_arrow(location = "bl", which_north = "true",
height = unit(1, "cm"), width = unit(1, "cm"),
pad_x = unit(0.3, "cm"), pad_y = unit(1.2, "cm"),
style = north_arrow_orienteering) +
coord_sf(xlim = c(-160, 135), ylim = c(15, 70))
但我收到错误消息:
“坐标系已经存在。添加新的坐标系,它将替换现有的。错误:stat_sf 需要以下缺少的美学:几何运行rlang::last_error()
以查看错误发生的位置。另外:警告消息:忽略未知的美学:x,y”
此外,我希望为橙色点添加一个说明“站点”的图例,并且我使用过
site_map + theme(legend.position=c(0.9, 0.1))
为此,但它不显示。
对于这方面的任何想法或资源,我将不胜感激。我研究了几种方法,但似乎都不适用于这个情节。谢谢!