Adding scale bar to ggplot map

前端 未结 4 543
自闭症患者
自闭症患者 2020-12-14 20:06

I\'ve produced this map in ggplot2:

library(maptools); library(ggplot2)
data(wrld_simpl)
world <- fortify(wrld_simpl)
worldUk <- subset(wo         


        
4条回答
  •  孤城傲影
    2020-12-14 20:37

    Another option is annotation_scale from the ggspatial package. Some more hints on this blog post.

    library(ggplot2)
    library(maptools)
    data(wrld_simpl)
    
    world_sf <- sf::st_as_sf(wrld_simpl)
    worldUk <- subset(world_sf, NAME == 'United Kingdom')
    

    Plot the layer and add the scale bar.

    library(ggspatial)
    
    ggplot() +
      geom_sf(data = worldUk) +
      annotation_scale()
    

提交回复
热议问题