连接多个组的stat_summary平均值

问题描述 投票:0回答:1

我对我所需要的外观感兴趣。但是,如果不需要,我不想使用facet_wrap或facet_grid。 我希望我能够简单地使用

group = interaction(condition, group)

,但是我会遇到错误。

enter image description here

由于您没有提供应用的代码

stat_summary

或您收到的错误消息只能猜测可能是什么问题。
但这是一个选择,是添加每个组和条件的平均值和标准误差以及连接每个条件组的行。关于使用X轴的问题,我添加了一个

scale_x_discrete

迫使离散量表: enter image description herelibrary(tidyverse) set.seed(123) df %>% mutate( x = as.numeric(factor(condition)), x_dodge = scales::rescale( as.numeric(factor(group)), to = .25 * c(-1, 1) ), group_jitter = x + jitter(x_dodge, 0.5), grouping = interaction(subject, condition), x_mean = x + x_dodge ) %>% ggplot(aes(x = condition, y = value, group = grouping)) + geom_line(aes(x = group_jitter), alpha = 0.2) + geom_point(aes(x = group_jitter, colour = group)) + stat_summary( geom = "line", aes(x = x_mean, group = condition), fun = mean ) + stat_summary( aes(x = x_mean, group = condition), fun.data = mean_se ) + scale_x_discrete(limits = c("A", "B"))

r ggplot2 facet-wrap geom
1个回答
0
投票

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.