如何解决向 ggmap 图中添加指北针和比例尺
我在绘图中遇到指北针和比例尺的问题。
我使用 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,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,scale = 0.2) +
ggsn::scalebar(x.min = -160,dist = 5,dd2km = TRUE,model = "wgs84",height = 0.5,st.dist = 0.5)
我也试过
site_map +
geom_sf(data = site_df,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,pad_x = unit(0.3,pad_y = unit(1.2,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))
为此,但它不显示。
如果您对此有任何想法或资源,我将不胜感激。我研究了几种方法,但似乎没有一种方法适用于这个情节。谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。