2014-01-30 141 views
2

我需要繪製一些東西,我的數據在previous post中有效,這在處理ggplot2方面幫了我很大忙。 (在之前的文章中,我需要變量miht.binned的分位數來裝箱以下情節,但由於涉及到正式佈局,我將從一個沒有該裝倉變量的更簡單的情節開始。)R ggplot2:繪圖中的點,線和誤差線不一致

我目前最好的情節版本是: enter image description here

我幾乎滿意,除了點,線和酒吧似乎重疊不一致。特別是,當你看T1的負面團體時,它會被看起來不太專業的黑色線條覆蓋。有沒有辦法解決這個問題,並使重疊更加一致,有意義?該問題與導出格式無關(圖片,pdf)。

這個陰謀代碼:

pd <- position_dodge(.2) 
ggplot(MyData, aes(x=time, y=ias, colour=GROUP, group=GROUP, 
           shape=GROUP)) + 
    stat_summary(fun.data = "mean_se", geom="errorbar",position=pd) + 
    stat_summary(fun.y="mean", geom="point", size=8,position=pd) + 
    stat_summary(fun.y="mean", geom="line",position=pd) + 
    scale_x_discrete(breaks=c("0", "1", "2"), labels=c("T0", "T1", "T2"))+ 
    coord_cartesian(ylim=c(2, 7)) + 
    scale_y_continuous(breaks=seq(2, 6, 2)) + 
    scale_color_manual(values=c("gray30", "gray50","gray70"),name ="Gruppe", 
              breaks=c("baseline", "negative", "neutral"), 
              labels=c("Baseline", "Attend-negative", "Attend-neutral")) + 
    scale_shape_discrete(name ="Gruppe", 
         breaks=c("baseline", "negative", "neutral"), 
         labels=c("Baseline", "Attend-negative", "Attend-neutral")) + 
    theme(
    panel.grid.major.y = element_line(colour = "gray80", size = NULL, linetype = NULL, # horizontale Linien 
             lineend = NULL) 
    ,panel.grid.minor.y = element_line(colour = "gray90", size = NULL, linetype = NULL, 
             lineend = NULL) 
    ,panel.grid.major.x = element_blank()   # vertikale Linien 
    ,panel.grid.minor.x = element_blank() 
    ,legend.background = element_rect(fill = "white", colour = "white") # Legende 
    ,legend.key = element_rect(fill = "white", colour = "white") 
    ,panel.background = element_rect(fill = "white", colour = "white", size = NULL, # Panel Hintergrund 
            linetype = NULL) 
    ,axis.line = element_line(colour = "black", size=.5) 
    ,axis.ticks.x = element_line(colour = "black", size=.5) 
    ,axis.ticks.y = element_line(colour = "black", size=.5) 
    ,axis.ticks.length = unit(0.5, "cm") 
    ,axis.ticks.margin = unit(.3, "cm") 
    ,axis.title.x = element_text(family = NULL, face = "bold", size = 11,vjust=0.1) 
    ,axis.title.y = element_text(family = NULL, face = "bold", size = 11,vjust=0.1) 
    ,axis.text=element_text(colour="black") 
    ,legend.title = element_text(family = NULL, face = "plain", size = 11) 
    ,legend.text = element_text(family = NULL, face = "plain", size = 9) 
) + 
    xlab("Messzeitpunkt")+ 
    ylab("State-KA (M)") 

回答

3

只要改變在您需要的順序stat_summary()調用的順序(它們在實際的情節繪製在他們被稱爲在你的代碼的順序) - 第一errorbars,然後線和點作爲最後。

+ stat_summary(fun.data = "mean_se", geom="errorbar",position=pd) + 
    stat_summary(fun.y="mean", geom="line",position=pd) + 
    stat_summary(fun.y="mean", geom="point", size=8,position=pd) 
+0

令人驚訝的簡單。謝謝,我在幾分鐘內接受。 – entne