无法重新排序geom_ribbon级别R.

时间:2016-08-09 05:07:20

标签: r ggplot2 facet

我一直遇到这个问题,无法弄清楚如何解决它。我在绘制数据时使用geom_ribbon创建95%CI波段;但是,当我重新排序级别以更改构面中的绘图顺序时,我的标签和数据会移动,但我的geom_ribbon却没有。这是一张图片:

enter image description here

DiffDFCollapsed$Condition<-factor(DiffDFCollapsed$Condition, levels=c("No Response - Bimanual","Unimanual - Bimanual","No Response - Unimanual"))
DiffDFAll$Condition<-factor(DiffDFAll$Condition, levels=c("No Response - Bimanual","Unimanual - Bimanual","No Response - Unimanual"))

p1<-print(ggplot(DiffDFCollapsed, aes(Time, MUERD,group=Condition,colour=Condition)) +
    geom_line(size=1) +
    scale_x_continuous(breaks=c(12,37,62,88,113,138,163,189),labels=c("-1000", "0", "1000","2000","3000","4000","5000","6000")) +

    geom_hline(yintercept=0)+
    geom_ribbon(aes(group=Condition,ymin=DiffDFCollapsed$CI_Low, ymax=DiffDFCollapsed$CI_High), linetype=2,alpha=0.3) +
    facet_wrap(~Condition,ncol=3)+
    ylab("Theta-Evenet Related Power (log transformed)")+
    xlab("TIME (in ms)")+
    theme(text=element_text(size=8),panel.background=element_rect(fill="white"),panel.border=element_rect(fill=NA),legend.position="none")) 

如果需要,我可以添加数据文件,但我认为我遗漏了一些简单的东西。

1 个答案:

答案 0 :(得分:1)

GAH !!!你不知道吗?只要我花时间发布一个问题,我就弄明白了。我需要改变这个:

geom_ribbon(aes(group=Condition,ymin=DiffDFCollapsed$CI_Low, ymax=DiffDFCollapsed$CI_High), linetype=2,alpha=0.3) +

到此:

geom_ribbon(data=DiffDFCollapsed,aes(ymin=CI_Low, ymax=CI_High), linetype=2,alpha=0.3)