ggplot图例键宽度由标签长度决定

无论关联标签的大小如何,我都希望ggplot2图例具有恒定宽度的键。

例如

 library(plyr)
 library(tidyverse)

 mtcars %>% 
   group_by(cyl,gear) %>%
   tally %>% 
   mutate(
     gear = gear %>% 
     plyr::mapvalues(
       3:5,c(
         "3 g short","4 gears medium","Five gears long label"
       )
     )  
   ) %>% 
   ggplot(
     aes(factor(cyl),n,fill = gear)
   ) +
   geom_col(
     color = "grey10",size = .1
   ) +
   scale_fill_grey(
     guide = guide_legend(label.position = "bottom")
   ) +
   theme_minimal() +
   theme(
     legend.position = "bottom"
   )

返回

ggplot图例键宽度由标签长度决定

根据标签长度的不同,三个灰色填充阴影显示为具有不同的宽度。如何确保填充键条目的大小都相同?

zhikejie 回答:ggplot图例键宽度由标签长度决定

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3077900.html

大家都在问