![](/img/trans.png)
[英]How to plot multiple lines with horizontal error bars from a dataframes using ggplot2 [in R]?
[英]R ggplot2: Points, lines and error bars in plot overlap inconsistently
我需要绘制一些东西,我的数据在以前的文章中可用,这对我处理ggplot2有很大帮助。 (在上miht.binned
文章中,我需要下面的图由变量miht.binned
的分位数进行分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)")
只需按照需要的顺序更改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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.