放大GGPLOT2传说

问题描述:

我有这样的情节Rggplot2 enter image description here放大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”线是虚线的,因为框太小。

我该如何放大它?

我很想有类似的东西: enter image description here

+0

看看你可以在这里改变的传奇主题http://docs.ggplot2.org/0.9.2.1/theme.html – user20650

尝试

# 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_legendhere

这会给你

enter image description here

您可以使用keywidthkeyheight操纵关键多少“延伸”到两个方向。使用title.position,direction等,您可以进一步调整图例。

请注意,由于您有多个合并的图例,因此您需要指定所有合并比例的指南。我首先将外部指南作为对象进行简化。