使用 ggsn 包在 ggplot 对象中添加指北针

问题描述 投票:0回答:0

结合ggplot、ggmap构建了如下图:

ggTun <- ggmap(TUN_map) +                 
  geom_point( data = XY_EC_sf4326_df,    aes(x = lon, y = lat), col="red",size =  2.5   )   +
  geom_path(  data = xyBord_Tunis4326_df,aes(x = lon, y = lat), linewidth =  1.0   )                 + 
  xlab("Longitude (°E)") + ylab("Latitude (°S)" )                                               +
  theme(axis.text.x  = element_text(size = 20),axis.text.y  = element_text(size = 20) )         +
  theme(axis.title.x = element_text(size = 26),axis.title.y = element_text(size = 26) )         +
  theme(legend.title=element_text(size=15),legend.text=element_text(size=15),legend.position = c(0.93,    0.13)) + scale_color_gradientn(colours = c('#5749a0', '#0f7ab0', '#00bbb1',
                                             '#bef0b0', '#fdf4af', '#f9b64b',
                                             '#ec840e', '#ca443d', '#a51a49'))

并使用 ggsn 添加比例尺

test0 <- ggTun +  ggsn::scalebar(x.min = leftTun+0.015,   x.max = rightTun, 
                                 y.min = bottomTun+0.015, y.max = topTun, 
                                 model = "WGS84",  dist_unit = "km", transform = TRUE,
                                 location = "bottomleft", height = 0.015, dist = 2, 
                                 st.size = 3, border.size = 0.8)

但是,当我尝试使用以下命令添加指北针时:

test1 <- test0 + ggsn::north(x.min = leftTun+0.015,   x.max = rightTun, 
                             y.min = bottomTun+0.015, y.max = topTun, scale = 1.5)

我收到以下错误:

我注意到“annotation_custom”问题,但我没有找到解决它的方法。非常感谢任何帮助。

r ggplot2 ggmap
© www.soinside.com 2019 - 2024. All rights reserved.