1

I have trouble to make the error bar through ggplot2 with my dataset.

Here is the code, it seems will be fine without errorbar:

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

Here is the error I got:

Error: Aesthetics must be either length 1 or the same as the data (4): y, fill

Here is the link of my dataset: https://drive.google.com/file/d/1RLhZSaWDx5pVrrtlGAv-qGRG5uVeJcrM/view?usp=sharing

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Kat
  • 11
  • 1
  • 3
    Welcome to SO. To get help on this site, try to reproduce the problem with a smaller dataset that you can share with `dput`. That way people can help you by simply copying and pasting from your post rather than reading your whole dataset and installing the necessary packages. Check out [this link] (https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on producing a reproducible example if you're unsure of how. – astrofunkswag Jan 29 '19 at 21:38
  • 1
    Thank you everyone..I actually figured it out! I put the wrong variable.... – Kat Jan 29 '19 at 23:11

0 Answers0