我正在尝试在 R 中获取我的数据图表,但由于某种原因,虽然代码完美地适用于数据的其他部分,但我创建的图表缺少点(平均值)和错误栏......什么我可不可以做?
dplyr::select(num, gvent.info:gvent.soc, group) %>%
tidyr::gather(Activity, Score, -c(num, group)) %>%
dplyr::mutate_at("group", as.factor) %>%
mutate(zScore = scale2(Score),
Score.music.C = Score-mean(Score[Activity=="gvent.mus"], na.rm=T))%>%
group_by(group)%>%
mutate(Score.music.C2 = Score-mean(Score[Activity=="gvent.mus"], na.rm=T))%>%
ungroup()
tmp.df1 <- na.omit(tmp.df)
tmp.df1$Activity <-
factor(tmp.df1$Activity,
levels=c('gvent.mus', 'gvent.info', 'gvent.ent', 'gvent.foo',
'gvent.spo', 'gvent.soc'),
labels=c('Music', 'Information', 'Entertainment', 'Food',
'Sport', 'Socializing'))
tmp.df1$group <- factor(tmp.df1$group, levels = c("1", "2", "3"),
labels = c("General Population", "Haredi & Religious",
"Arab Sector"))
tmp.df1$Activity <- relevel(tmp.df1$Activity, ref = "Music")
model0 <- lmer(Score ~ 1 + (1|num), data = tmp.df1)
model1 <- lmer(Score ~ Activity + (1|num), data = tmp.df1)
model2 <- lmer(Score ~ Activity + group + (1|num), data = tmp.df1)
model3 <- lmer(Score ~ Activity * group + (1|num), data = tmp.df1)
tab_model(model0, model1, model2, model3, show.se = F, show.loglik = F, show.aic = F, show.r2 = T,
p.style = "stars", show.ci = 0.95, show.icc=T)
# plot by Activity x culture
ef <- effect("Activity:group", model3)
summary(ef)
x <- as.data.frame(ef)
x$Activity <- factor(x$Activity,
levels = c('gvent.mus', 'gvent.info', 'gvent.ent', 'gvent.foo',
'gvent.spo', 'gvent.soc'),
labels=c('Music', 'Information', 'Entertainment', 'Food',
'Sport', 'Socializing'))
a = ggplot(tmp.df1, aes(Activity, Score, fill=group)) +
geom_boxplot(stat = "boxplot",position = "dodge2",outlier.shape = NA, coef = 0) +
geom_errorbar(data = x, aes(y=fit, ymin=lower, ymax=upper), width=0.1, position = position_dodge(0.77)) +
geom_point(data = x, aes(y=fit), position = position_dodge(0.77)) +
scale_fill_manual(name = "Sectors", labels = c("Arab sector", "General population", "Haredi and religious Jews"),
values = c("orangered", "steelblue1","yellow1")) +
coord_cartesian(ylim = c(-3, 3)) +
ylab("Goal's Importance") +
theme_bw(base_size=13) +
theme(axis.text.x = element_text(angle = 345),
panel.grid.major.x = element_blank())
a```