Showing posts with label boxplots. Show all posts
Showing posts with label boxplots. Show all posts
Monday, June 4, 2012
Boxplot with Means
boxplots as alternative to barplot with error bars
- a more informative alternative to this barplot with errorbars
- using the movies example data set (part of the ggplot2 package)
- cut the year variable in 15 equal intervals gives the new variable years
- map this new year var to x, budget to y and colour also to years (aes(x=years,y=budget,colour=years))
- add a layer boxplot, set the fill colour for the bars to black
- format the y axis (use dollar formatting)
- change the x axis tick labels with a text theme: rotate the tick labels (angle=270), position adjustment with hjust and vjust
- we do not need a legend for he colours because the information is contained in the x axis, so get rid of it: opts(legend.position="none")
movies$years <- cut(movies$year,breaks=15) ggplot(movies, aes(x=years,y=budget,colour=years)) + geom_boxplot(fill="black") + scale_y_continuous(labels=dollar) + stat_summary(fun.y="mean",geom="point") + opts(axis.text.x = theme_text(angle=270,hjust=0,vjust=1)) + opts(legend.position="none")
Warnmeldungen: 1: Removed 53573 rows containing non-finite values (stat_boxplot). 2: Removed 53573 rows containing missing values (stat_summary).

