sb = as.data.frame(Seatbelts)
sb$law = as.factor(sb$law)
##THIS CODE WORKS, BUT NO LABELS
RearLaw=subset(sb,law==1)
RearNoLaw=subset(sb,law==0)
ggplot(sb,aes(x=law,y=rear))+geom_boxplot()+labs(x="Seatbelt Laws (1=TRUE)",
y="# of Rear Deaths & Serious Injuries",title="Rear Deaths With & Without Seatbelt Laws")
##THIS CODE DOESN'T WORK
ggplot(sb,aes(x=law,y=rear))+geom_boxplot()+labs(x="Seatbelt Laws (1=TRUE)",
y="# of Rear Deaths & Serious Injuries",title="Rear Deaths With & Without Seatbelt Laws")+
geom_text(x=boxplot.stats(RearLaw$rear),label=fivenum(RearLaw$rear))
I am trying to create side-by-side boxplots with the summary statistics for RearLaw and RearNoLaw displayed next to their respective boxes, but I keep getting the message: "Error: Aesthetics must be either length 1 or the same as the data (192): x and label". I think this is because fivenum generates 5 outputs and my df has 192 items, but I only want those five to be displayed. The code above includes an attempt at labeling the RearLaw box (ie law=1), but I would like to label the RearNoLaw box as well (law=0) if possible. I'm entirely new to R and have never posted here, so please let me know if there's any other information to provide.
