咨询:R中可视化含时间点、分组、情绪的反应时数据集的替代图表
适合反应时重复测量数据的替代图表类型
你的数据属于混合设计重复测量数据(组间变量:组别;组内变量:时间点、情绪类型),除了柱状图,以下几种图表更能挖掘数据特征:
1. 箱线图(Box Plot)
- 核心价值:相比柱状图只展示均值,箱线图能直观呈现数据分布、中位数、四分位距及异常值,特别适合反应时这类易出现极端值的指标。
- R代码示例:
library(ggplot2) # 导入样本数据集 df <- data.frame( participant = c("AA", "AA", "AA", "AA", "AA", "AA", "AB", "AB", "AB", "AB", "AB", "AB"), emotion = c("happy", "happy", "sad", "sad", "neutral", "neutral", "happy", "happy", "sad", "sad", "neutral", "neutral"), group = c("groupA", "groupA", "groupA", "groupA", "groupA", "groupA", "groupB", "groupB", "groupB", "groupB", "groupB", "groupB"), time = c("t1", "t2", "t1", "t2", "t1", "t2", "t1", "t2", "t1", "t2", "t1", "t2"), rt = c(47.09, 40.09, 33.99, 33.99, 104.97, 98.75, 54.65, 64.65, 53.99, 43.99, 24.97, 98.75) ) # 绘制分面箱线图 ggplot(df, aes(x = time, y = rt, fill = emotion)) + geom_boxplot(position = position_dodge(width = 0.8)) + facet_wrap(~group) + labs(title = "不同组别、时间点下的情绪面孔反应时分布", x = "时间点", y = "反应时", fill = "情绪类型") + theme_minimal()
2. 折线图(Line Plot)
- 核心价值:聚焦时间变化趋势,清晰展示同一组别/被试从T1到T2的反应时变化,能快速识别交互效应(比如Group A在neutral情绪下反应时下降,Group B反而上升)。
- R代码示例:
library(dplyr) library(ggplot2) # 计算各条件下的均值与标准误 df_summary <- df %>% group_by(group, time, emotion) %>% summarise(mean_rt = mean(rt), se_rt = sd(rt)/sqrt(n()), .groups = "drop") # 绘制带误差棒的折线图 ggplot(df_summary, aes(x = time, y = mean_rt, color = emotion, group = emotion)) + geom_line(linewidth = 1) + geom_point(size = 3) + geom_errorbar(aes(ymin = mean_rt - se_rt, ymax = mean_rt + se_rt), width = 0.2) + facet_wrap(~group) + labs(title = "不同组别情绪面孔的反应时随时间变化趋势", x = "时间点", y = "平均反应时", color = "情绪类型") + theme_minimal()
3. 小提琴图(Violin Plot)
- 核心价值:结合箱线图和密度图的优势,展示数据分布的形状,能直观看出反应时是偏态还是正态分布,适合小样本数据呈现分布特征。
- R代码示例:
ggplot(df, aes(x = emotion, y = rt, fill = time)) + geom_violin(position = position_dodge(width = 0.8), alpha = 0.7) + geom_boxplot(position = position_dodge(width = 0.8), width = 0.2, color = "black") + facet_wrap(~group) + labs(title = "不同组别、时间点下情绪面孔的反应时分布形状", x = "情绪类型", y = "反应时", fill = "时间点") + theme_minimal()
4. 原始点图(Dot Plot)
- 核心价值:保留所有原始数据点,避免均值掩盖个体差异,适合样本量不大的情况,能直接看到每个被试的反应时表现。
- R代码示例:
ggplot(df, aes(x = emotion, y = rt, color = time)) + geom_jitter(width = 0.2, size = 2, alpha = 0.8) + stat_summary(fun = mean, geom = "point", shape = 18, size = 4, color = "black") + facet_wrap(~group) + labs(title = "不同组别情绪面孔的原始反应时数据", x = "情绪类型", y = "反应时", color = "时间点") + theme_minimal()
5. 交互效应图(Interaction Plot)
- 核心价值:专门展示多因素交互关系,清晰呈现组别、时间、情绪三者之间的交互效应,快速定位差异显著的条件组合。
- R代码示例:
# ggplot2分面交互图 ggplot(df_summary, aes(x = time, y = mean_rt, color = emotion)) + geom_line(aes(group = emotion)) + geom_point() + facet_wrap(~group) + labs(title = "组别×情绪×时间的交互效应", x = "时间点", y = "平均反应时", color = "情绪类型") + theme_minimal()
内容的提问来源于stack exchange,提问作者Christina
相关产品推荐
相关产品推荐

