提问人:Maya Eldar 提问时间:6/12/2022 最后编辑:Maya Eldar 更新时间:6/13/2022 访问量:146
R:如何在折线图上添加子组之间的显著性差异
R: how to add significance differences between sub groups on a line plot
问:
我有一个 3 个不同组的折线图,除了显着差异外,我还想在图表上显示子组之间差异的显着性。例如,将 3 个人群中每个人群在 1 岁时体重差异的显著性相加。我看到了这个函数,但未能在图表中的线条之间垂直使用它。
我目前的代码:stat_compare_means()
library(tidyverse)
#pivot data into long format
df <- data.frame(
stringsAsFactors = FALSE,
ID = c(1L, 2L, 3L, 4L, 5L),
POPULATION = c("A", "A", "B", "B", "C"),
weight.at.age.1 = c(13.37, 5.19, 7.68, 6.96, 10.35),
weight.at.age.2 = c(14.15, 15.34, 6.92, 15.12, 8.86),
weight.at.age.3 = c(17.36, NA, 19.42, 36.39, 26.33)
) %>%
pivot_longer(cols = weight.at.age.1:weight.at.age.3,
names_to = 'age',
values_to = 'weight') %>%
mutate(age = str_remove(age, 'weight.at.age.'))
#plot data
ggline(data = df,
mapping = aes(x = age,
y = weight, add = "mean_se", color=POPULATION))+
stat_compare_means(aes(group = POPULATION), method = "anova", label = "p.signif",
label.y = c(56))
啧!
答: 暂无答案
评论
Error in f(...) : Can only handle data with groups that are plotted on the x-axis
stat_compare_means