Space between gpplot2 horizontal legend elements

前端 未结 6 1085
一生所求
一生所求 2020-12-17 18:17

I have a ggplot2 plot as follows:

library(ggplot2)

ggplot(mtcars, aes(factor(cyl), fill=factor(cyl))) + 
    geom_bar() +
    coord_flip() +
    theme(legen         


        
6条回答
  •  一生所求
    2020-12-17 18:57

    With ggplot2 v3.0.0, we can use legend.spacing.x to manipulate the space between legend keys.

    library(ggplot2)
    
    ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + 
      geom_bar() +
      coord_flip() +
      theme(legend.position = 'top') +
      guides(fill = guide_legend(title = "Cyl")) +
      theme(legend.spacing.x = unit(0.5, 'cm'))
    

    Created on 2018-05-30 by the reprex package (v0.2.0).

提交回复
热议问题