将ggsn比例尺拟合到ggmap对象时出现新错误

时间:2019-05-01 22:00:55

标签: r ggplot2 ggmap

我最近重新运行了ggmap代码,并且ggmap的ggsn比例尺不再起作用。删除比例尺功能后,即可成功制作ggmap。几周前它已经工作了,但是现在抛出了以下错误:

  

st_geometry(legend2)中的错误<-NULL:找不到函数   “ st_geometry <-”

这是一个新错误,我很困惑,因为我没有直接调用该函数。

下面是我正在使用的ggmap代码块和依赖项/库

if(!requireNamespace("devtools"))install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggplot2)
register_google(key = "REDACTED")

devtools::install_github('oswaldosantos/ggsn')

MAD_map <- ggmap(get_map(location=c(-89.410087,43.074243), 
                         zoom=14, scale=4, source = "stamen", 
                         maptype = "terrain")) + 
  ggsn::scalebar(x.min = -89.387949, x.max = -89.387952,
                 y.min =43.090330, y.max = 43.0919, location="topright", 
                 dist = .5, transform = TRUE, dist_unit = "km",
                 model = "GRS80", height =.2, st.size = 3, st.dist = .5) + 
  geom_point(data = Location_points_DF,
             aes(x=long,y=lat,color= dot.color, size=5),
             shape = c(12, shape.list[c(1,3,5,7,8)]))  + 
  scale_shape_manual(values= c(12, shape.list[c(1,3,5,7,8)]))+
  scale_color_manual(values = Location_points_DF$dot.color )  + 
  annotate("text", x = Location_points_DF$long, y = Location_points_DF$lat, 
           label = c("3","5","6","1","4","2"), size = 5) +
  theme(legend.position="none", 
        axis.title.x=element_blank(),  
        axis.text.x=element_blank(), 
        axis.ticks.x=element_blank(), 
        axis.title.y=element_blank(), 
        axis.text.y=element_blank(), 
        axis.ticks.y=element_blank() )

1 个答案:

答案 0 :(得分:0)

0.5.2版为我解决了此问题:https://github.com/oswaldosantos/ggsn/issues/45

尝试使用最新版本,看看是否仍然存在问题:https://github.com/oswaldosantos/ggsn