我需要绘制一些东西,我的数据可以在previous post中获得,这对我处理ggplot2有很大帮助。 (在上一篇文章中,我需要通过变量miht.binned
的分位数来分类下面的图,但是在正式布局中,我从没有该分箱变量的更简单的绘图开始。)
我目前最好的情节版本是:
我几乎感到满意,除了点,线和条似乎不一致重叠。特别是,当你看到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)")
答案 0 :(得分:3)
只需按照您需要的顺序更改stat_summary()
次调用的顺序(它们按照您在代码中调用的顺序在实际绘图中绘制) - 第一个错误栏,然后是行和点作为最后一个。
+ 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)