gpplot2水平图例元素之间的空间 [英] Space between gpplot2 horizontal legend elements
问题描述
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))
因为
对图形设计师造成的任何噩梦抱歉。
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屋!