我很难用数据集通过ggplot2制作错误栏。
这是代码,没有错误栏似乎没问题:
library(psych)
library(ggplot2)
Clean$Creativity = as.factor(Clean$Creativity)
Clean$Facial = as.factor(Clean$Facial)
Clean2 = describeBy(Clean$Attractiveness, list(Clean$Creativity, Clean$Facial), mat=TRUE, digits=2)
Clean2
names(Clean2)[names(Clean2)== 'group1'] = 'Creativity'
names(Clean2)[names(Clean2)=='group2'] = 'Facial'
levels(Clean2$Creativity)[levels(Clean2$Creativity)=='0'] = 'Less Creative'
levels(Clean2$Creativity)[levels(Clean2$Creativity)=='1'] = 'Creative'
levels(Clean2$Facial)[levels(Clean2$Facial)=='0'] = 'Less Attractive'
levels(Clean2$Facial)[levels(Clean2$Facial)=='1']='Attractive'
Clean2$se = Clean2$sd/sqrt(Clean2$n)
Clean2
limits = aes(ymax = mean + (1.96*se), ymin=mean - (1.96*se))
dodge = position_dodge(width=0.9)
apatheme=theme_bw()+
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.border=element_blank(),
axis.line=element_line(),
text=element_text(family='Times'))
plot.2way = ggplot(Clean2, aes( x = Facial, y = Attractiveness, fill = Personality))+
geom_bar(stat = 'identity', position=dodge)+
geom_errorbar(limits, position=dodge, width=0.25)+
apatheme+
ylab('Attractiveness')+
scale_fill_grey()
plot.2way
这是我遇到的错误:
错误:美学的长度必须为1或与数据(4)相同:y,填充
这是我的数据集的链接: https://drive.google.com/file/d/1RLhZSaWDx5pVrrtlGAv-qGRG5uVeJcrM/view?usp=sharing