ggsn :: scalebar未被放置在角落

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

我正在尝试将比例尺添加到从Google获得的地图中。我想在左上角放置比例尺,但是它放置不正确(距离角落有点远)。我知道它与地图的范围有关,但是我不知道如何解决它。

library(ggplot2)
library(ggsn)
library(ggmap)

ca <- get_map(location = c(-124.29, 40.75, -123.91, 40.97), maptype = "terrain", source = "google", force = T)

ggmap(ca) + 
    coord_sf(crs = st_crs(4326), expand = FALSE) +
    scalebar(x.min = -124.29, x.max = -123.91, y.min = 40.75, y.max = 40.97, 
             location = "topleft", 
             dist = 5,
             dist_unit = "km", 
             transform = TRUE, 
             model = "WGS84",
             st.dist = 0.04)

enter image description here

r ggmap
1个回答
0
投票

您可以使用锚点调用来放置比例尺。

ggmap(ca) + 
  coord_sf(crs = st_crs(4326), expand = FALSE) +
  scalebar(x.min = -124.29, x.max = -123.91, y.min = 40.75, y.max = 40.97, 
           anchor = c(x =  -124.29+.002, y = 40.97-.005),
           location = "topleft", 
           dist = 5,
           dist_unit = "km", 
           transform = TRUE, 
           model = "WGS84",
           st.dist = 0.04)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.