放大GGPLOT2传说
问题描述:
我有这样的情节R
与ggplot2
放大GGPLOT2传说
这是由下面的代码画制作:
ggplot(mtcars) +
geom_smooth(fill='grey', alpha=0.3, span=0.1, aes(x=mpg, y=hp, color='AAA',linetype='AAA')) +
geom_smooth(fill='grey', alpha=0.3, span=0.9, aes(x=mpg, y=hp, color='BBB',linetype='BBB')) +
scale_colour_manual(name='test', values=c('AAA'='chocolate', 'BBB'='yellow')) +
scale_linetype_manual(name='test', values=c('AAA'='dashed','BBB'='solid')) +
theme_minimal() +theme(legend.position = "top")
问题:从传说中,它是不容易理解“AAA”线是虚线的,因为框太小。
我该如何放大它?
答
尝试
# create your legend guide
myguide <- guide_legend(keywidth = unit(3, "cm"))
# now create your graph
ggplot(mtcars) +
geom_smooth(fill='grey', alpha=0.3, span=0.1,
aes(x=mpg, y=hp, color='AAA',linetype='AAA')) +
geom_smooth(fill='grey', alpha=0.3, span=0.9,
aes(x=mpg, y=hp, color='BBB',linetype='BBB')) +
scale_colour_manual(name='test',
values=c('AAA'='chocolate', 'BBB'='yellow'),
guide = myguide) +
scale_linetype_manual(name='test',
values=c('AAA'='dashed','BBB'='solid'),
guide = myguide) +
theme_minimal() + theme(legend.position = "top")
见?guide_legend
和here。
这会给你
您可以使用keywidth
和keyheight
操纵关键多少“延伸”到两个方向。使用title.position
,direction
等,您可以进一步调整图例。
请注意,由于您有多个合并的图例,因此您需要指定所有合并比例的指南。我首先将外部指南作为对象进行简化。
看看你可以在这里改变的传奇主题http://docs.ggplot2.org/0.9.2.1/theme.html – user20650