我有两个数据帧,第一个:

enter image description here

第二个:

enter image description here

我使用第一个数据帧创建了如下所示的条形图.

enter image description here

虽然我没有使用每个一致性组中的se值在它上面放置错误条.

以下是我的代码:

ggplot(AAData_cong, aes(x=Congruency, y=joystick_reaction, fill = as.factor(Congruency)))+
  geom_bar(position=position_dodge(.5), size=.75,  width=0.5, colour="black", stat= "summary", fun= "mean") +
  geom_line(aes(group=participant), linetype = "dashed") + 
  geom_point(aes(group=participant), shape = 21, color = 'black')+
  # geom_errorbar(aes(ymin=RT_Cong$joystick_reaction-RT_Cong$se, ymax=RT_Cong$joystick_reaction+RT_Cong$se), width=.2,
  #                position=position_dodge(0.05))+
  theme_classic(base_size=18)+
  coord_cartesian(ylim = c(700, 1200))+ # set the y limits
  ylab("RT (ms)")+labs(fill="j")+
  theme(axis.title.y = element_text(size = rel(1), angle = 90,  vjust=1.25))+
  theme(axis.title.x = element_text(size = rel(1), angle = 0,  vjust=0))+
  theme(axis.text.x = element_text(size=rel(1)))+
  theme(axis.text.y = element_text(size=rel(1)))+theme(legend.position = "none")+
  theme(strip.text.x = element_text(size=9))+
  # from set 1 color brewer
  scale_fill_manual(values=c("#0571b0","#ca0020"))

提前谢谢您!

推荐答案

Df1是第一个数据帧 Df2是具有sd和se的第二个:

只需将其添加到代码中:

  geom_errorbar(data = df2, aes(ymin=joystick_reaction-sd, ymax= joystick_reaction  +sd), width=.2, position=position_dodge(.9)) 
library(tidyverse)

ggplot(df1, aes(x=Congruency, y=joystick_reaction, fill = as.factor(Congruency)))+
  geom_bar(position=position_dodge(.5), size=.75,  width=0.5, colour="black", stat= "summary", fun= "mean") +
  geom_line(aes(group=participant), linetype = "dashed") + 
  geom_point(aes(group=participant), shape = 21, color = 'black')+
  # geom_errorbar(aes(ymin=RT_Cong$joystick_reaction-RT_Cong$se, ymax=RT_Cong$joystick_reaction+RT_Cong$se), width=.2,
  #                position=position_dodge(0.05))+
  theme_classic(base_size=18)+
 # coord_cartesian(ylim = c(700, 1200))+ # set the y limits
  ylab("RT (ms)")+labs(fill="j")+
  theme(axis.title.y = element_text(size = rel(1), angle = 90,  vjust=1.25))+
  theme(axis.title.x = element_text(size = rel(1), angle = 0,  vjust=0))+
  theme(axis.text.x = element_text(size=rel(1)))+
  theme(axis.text.y = element_text(size=rel(1)))+theme(legend.position = "none")+
  theme(strip.text.x = element_text(size=9))+
  # from set 1 color brewer
  scale_fill_manual(values=c("#0571b0","#ca0020"))+
  geom_errorbar(data = df2, aes(ymin=joystick_reaction-sd, ymax= joystick_reaction  +sd), width=.2, position=position_dodge(.9)) 

enter image description here

R相关问答推荐

在R中,将一个函数作为输入传递给另一个函数时进行参数判断

如何将多个数据帧附加到R中的多个相应的CSV文件中?

是否有任何解决方案可以优化VSCode中RScript的图形绘制?

通过绘图 Select 线串几何体并为其着色

卸载安装了BRM的模型发出的警告

检测(并替换)字符串中的数学符号

更改编号列表的 colored颜色

如何在RMarkdown LaTex PDF输出中包含英语和阿拉伯语?

任意列的欧几里得距离

为什么在ggplot2中添加geom_text这么慢?

用值序列对行进行子集化,并标识序列开始的列

用关联字符串替换列名的元素

如何从R ggplot图片中获取SVG字符串?

提取一个列表中单个列的重复观察结果R

更新R中的数据表(使用data.table)

悬崖三角洲超大型群数计算导致整数溢出

按组内中位数分类

如何在R中添加标识连续日期的新列

使用卡环从R中的列中删除单位(&C)

真实世界坐标的逆st_变换