R(ggplot2):在aes()中使用形状或颜色时理解不同的行为

时间:2013-06-05 15:16:35

标签: r ggplot2

这是一个ggplot:

  ggplot(data.and.factors.prov,aes(x=Design.Complexity,y=FP,shape=factor(All.interactions))) + 
    stat_summary(fun.data=mean_cl_normal,position=position_dodge(width=0.5)) + 
    geom_blank() + 
    geom_smooth(method='lm',se=F,formula=y~x,colour='black')  + 
    scale_shape_manual(values=c(17,3,16,6,15,4),
                       name='Interactions',
                       labels=c('No interactions','All possible interactions','Randomly picked interactions\nand direct effects')) + 
    labs(x='Design.complexity',y='FP',title='Under Bonferroni Correction') + 
    opts(axis.line = theme_segment(colour = "black"),
        panel.grid.major = theme_blank(),
        panel.grid.minor = theme_blank(),
        panel.border = theme_blank(),
        panel.background = theme_blank()) + ylim(0.03,0.06)

enter image description here

如果我按组替换形状:

enter image description here

按颜色替换形状/组时:

ggplot(data.and.factors.prov,aes(x=Design.Complexity,y=FP,colour=factor(All.interactions))) + 
stat_summary(fun.data=mean_cl_normal,position=position_dodge(width=0.5)) + 
geom_blank() + 
geom_smooth(method='lm',se=F,formula=y~x,colour='black')  + 
scale_shape_manual(values=c(17,3,16,6,15,4),
                   name='Interactions',
                   labels=c('No interactions','All possible interactions','Randomly picked interactions\nand direct effects')) + 
labs(x='Design.complexity',y='FP',title='Under Bonferroni Correction') + 
opts(axis.line = theme_segment(colour = "black"),
    panel.grid.major = theme_blank(),
    panel.grid.minor = theme_blank(),
    panel.border = theme_blank(),
    panel.background = theme_blank()) + ylim(0.03,0.06)

enter image description here

同时使用颜色和组

enter image description here

为什么在使用形状时会得到3次回归,但在使用颜色时只获得1次回归?

使用颜色时如何获得3色回归?使用形状时如何才能获得1回归?

1 个答案:

答案 0 :(得分:0)

只需在geom_smooth()中删除color ='black',它就会自动为您提供3次回归。

如果你想要3个黑色回归,你可以在aes()中同时使用group = factor(All.interactions)和color = factor(All.interactions),并在geom_smooth()中保持color ='black'