我试图创建一个分组条形图,共有4条(没有支持的男性的愿望,没有支持的女性的愿望,得到支持的男性的愿望,得到支持的女性的愿望),加上误差条。变量“wish”是在1-5的范围内测量的,因此我试图相应地设置限制,但这导致图表中只显示误差条,而不显示“主”条,并出现以下错误消息:
警告消息:删除了包含缺失值(geom_bar()
)的4行。
ggplot(wish_c, aes(x=factor(esnonrom_t,
levels = c("0", "1"),
labels = c("Received no support (n = 89)", "Received support (n=795)")),
y=wish_for_partner_t1,
fill=factor(sex_gen,
levels = c("0", "1"),
labels=c("Men (n=427)", "Women(n=457)")))) +
geom_bar(position=position_dodge(), stat="identity") +
geom_errorbar(aes(ymin=wish_t1-se, ymax=wish_t1+se),
width=.2, # Width of the error bars
position=position_dodge(.9)) +
scale_y_continuous("Wish (1-5)", limits=c(1,5), breaks=seq(1,5, by =1)) +
theme_classic() +
scale_fill_brewer(palette = "Greys") +
labs(x = "Emotional support received
beyond the romantic relationship",
fill = "Gender",
title = "Wish by gender and emotional support")
1条答案
按热度按时间yacmzcpb1#
一种方法是使用
stat_summary()
。我创建了一个示例数据集: