R语言 如何使用geom_sf在图例和Map之间添加空格

6tr1vspr  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(109)

我试图用ggplot + geom_sf绘制Map,图例在Map上。如何在Map的底部(或填充)增加?我试过plot.margin = margin(b = 2),但它是保证金,然后整个情节增加的标题下,然后没有工作。
我的代码:

ggplot(shp_dados_ce) +
  geom_sf(aes(fill = populacao_2022), ) +
  theme_void() +
  scale_fill_viridis(
    trans = "log10"
    , name="Habitantes"
    , guide = guide_legend( 
      keyheight = 0.25
      , keywidth= 1
      , label.position = "bottom"
      , title.position = 'top'
      , nrow=1
    ) 
  ) +
  labs(
    title = "title",
    subtitle = "subtitle",
    caption = "caption"
  ) +
  theme(
    text = element_text(color = "#22211d"),
    panel.background = element_rect(fill = "#f5f5f2", color = NA),
    panel.border = element_rect(fill = NA, color = "green"),
    
    plot.background = element_rect(fill = "#f5f5f2", color = NA),
    plot.margin = margin(b = 2),
    plot.title = element_text(
      size= 16
      , hjust=0.05
      , vjust=0.05
      , color = "#4e4d47"
    ),
    plot.subtitle = element_text(
      size= 11
      , hjust=0.05
      , color = "#4e4d47"
      , margin = margin(
        b = -0.25
        , t = 5
      )
    ),
    
    legend.background = element_rect(fill = "green", color = NA),
    legend.box.background = element_rect(color = "black"),
    legend.position = c(0.5, 0.04),
    legend.text = element_text(size = 6),
    legend.title = element_text(size = 6),
    legend.margin = margin(l = 0.5 ,t = 2),
    legend.box.margin = margin(3,2,2,2)
  )

还有我的Map

谢谢.

eimct9ow

eimct9ow1#

使用legend.position = 'bottom'解决。
谢谢Allan Cameron的评论。

相关问题