![](/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.