You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于已完成的独立样本t检验结果创建箱线图等可视化图表?

Creating Visualizations for Your Independent Samples t-Test Results

Great job wrapping up your t-test and descriptive statistics! Since you’re already using tidyverse, we’ll lean on ggplot2 (included in the tidyverse suite) to build clear, informative visualizations tailored to your data. Here are a few practical options:

1. Basic Boxplot (Core Group Comparison)

This plot shows the spread, median, and outliers of BMIS scores across your HAPPY and SAD conditions:

# Basic boxplot
ggplot(BMIS_DATA, aes(x = CONDITION, y = BMIS)) +
  geom_boxplot(fill = "lightsteelblue", alpha = 0.7) +  # Customize fill color/transparency
  labs(
    title = "Distribution of BMIS Scores by Condition",
    x = "Experimental Condition",
    y = "BMIS Score"
  ) +
  theme_minimal()  # Clean, easy-to-read theme

2. Boxplot with Overlaid Mean Points

To highlight the group means you calculated in your descriptive stats, overlay them on the boxplot using your descriptive_statistics dataframe:

# Boxplot with mean markers
ggplot(BMIS_DATA, aes(x = CONDITION, y = BMIS)) +
  geom_boxplot(fill = "lightsteelblue", alpha = 0.7) +
  # Add red diamond markers for group means
  geom_point(data = descriptive_statistics, aes(y = mean),
             color = "darkred", size = 3, shape = 18) +
  labs(
    title = "BMIS Scores by Condition (with Group Means)",
    x = "Experimental Condition",
    y = "BMIS Score",
    caption = "Red diamond = Group Mean"
  ) +
  theme_minimal()

3. Boxplot with Significance Annotation

Since your t-test returned a highly significant result (p = 0.0005201), add a visual marker to draw attention to this finding:

# Boxplot with significance label
ggplot(BMIS_DATA, aes(x = CONDITION, y = BMIS)) +
  geom_boxplot(fill = "lightsteelblue", alpha = 0.7) +
  geom_point(data = descriptive_statistics, aes(y = mean),
             color = "darkred", size = 3, shape = 18) +
  # Add t-test results as text between the two groups
  annotate("text", x = 1.5, y = max(BMIS_DATA$BMIS) + 2,
           label = "t(44) = 3.75, p < 0.001",
           fontface = "bold") +
  labs(
    title = "BMIS Scores by Condition (with Significance)",
    x = "Experimental Condition",
    y = "BMIS Score",
    caption = "Red diamond = Group Mean | Stats from independent samples t-test"
  ) +
  theme_minimal()

4. Optional: Violin Plot (Detailed Distribution View)

If you want a richer look at how scores are distributed within each group, a violin plot paired with a boxplot works well:

# Violin plot with boxplot overlay
ggplot(BMIS_DATA, aes(x = CONDITION, y = BMIS)) +
  geom_violin(fill = "palegreen", alpha = 0.5) +  # Shows distribution shape
  geom_boxplot(width = 0.2, fill = "white") +  # Overlays key summary stats
  labs(
    title = "BMIS Score Distribution by Condition",
    x = "Experimental Condition",
    y = "BMIS Score"
  ) +
  theme_minimal()

Quick Tips:

  • Adjust colors, sizes, and text positions in the code to match your preferred style.
  • The x = 1.5 in the annotate() function centers the significance text between your two conditions (HAPPY = x=1, SAD = x=2).
  • Tweak the +2 in max(BMIS_DATA$BMIS) + 2 to adjust how far above the highest data point the significance text sits.

内容的提问来源于stack exchange,提问作者Iesha Tucker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 17:07:45