gpplot2水平图例元素之间的空间 [英] Space between gpplot2 horizontal legend elements

查看:148
本文介绍了gpplot2水平图例元素之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  library(ggplot2)

ggplot(mtcars ,aes(factor(cyl),fill = factor(cyl)))+
geom_bar()+
coord_flip()+
theme(legend.position ='top')+
guides(fill = guide_legend(title = NULL))

我想要在填充元素如下:

解决方案

它确实看起来像主题(legend.text = element_text(margin = margin(r = 2,unit ='in')))正确的方式来完成任务,但这根本就没有做任何事。



相反,(而不是第一次)我回到Microsoft Word

  ggplot(mtcars,aes(factor( ())+ 
geom_bar()+
coord_flip()+
主题(legend.position ='top')+
guides(fill = guide_legend(title = NULL))



因为 8 上也有空格,所以它有点偏离中心,但如果你只是将它们粘贴到以前的标签上,你可以按照自己的喜好将其粘贴。



对图形设计师造成的任何噩梦抱歉。


I have a ggplot2 plot as follows:

library(ggplot2)

ggplot(mtcars, aes(factor(cyl), fill=factor(cyl))) + 
    geom_bar() +
    coord_flip() +
    theme(legend.position = 'top') +
    guides(fill = guide_legend(title=NULL))

I'd like add spacing between the fill elements as follows:

解决方案

It really seems something like theme(legend.text = element_text(margin = margin(r = 2, unit = 'in'))) would be the right way to accomplish the task, but that doesn't do anything at all.

Instead, (and not for the first time) I fall back on the Microsoft Word style of alignment-hacking, i.e. just add spaces:

ggplot(mtcars, aes(factor(cyl), fill=factor(paste(cyl, '                    ')))) + 
    geom_bar() +
    coord_flip() +
    theme(legend.position = 'top') +
    guides(fill = guide_legend(title=NULL))

Because there's spaces on the 8 as well, it's a little off-center, but if you just paste them onto the previous labels you can nudge them around as you like.

Apologies for any nightmares caused to graphic designers.

这篇关于gpplot2水平图例元素之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆