average dashline

7 views
Skip to first unread message

J H

unread,
Mar 4, 2014, 4:53:48 PM3/4/14
to ggp...@googlegroups.com
in the ggplot2 boxplot the median gets calculated, but how about mean.  what is the best way to add it?  I prefer ggplot2 to calculate it.  I know geom_vline or hline adds it if I bring the data in, but preference would be for R do it based on how my x axis is separated.  Thanks.

JiHO

unread,
Mar 5, 2014, 6:05:57 AM3/5/14
to J H, ggplot2
You would need to write a new stat_* function that works as
stat_boxplot (i.e. outputs the same values in a data.frame, see
?stat_boxplot).

*But* this is probably a bad idea. Boxplots are not just defined by
their visual aspect, the fact that the central line is the median, the
whiskers extend to 1.5 * the interquartile range etc. all participate
in the definition of what a botplot is. So by making a non-standard
boxplot, you will be confusing your readers. I would advise you to
create a new, different looking plot altogether if you want to show
the mean instead of the median.

Jean-Olivier Irisson
—
Université Pierre et Marie Curie
Laboratoire d'Océanographie de Villefranche
181 Chemin du Lazaret 06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://www.obs-vlfr.fr/~irisson/
Send me large files at: http://www.obs-vlfr.fr/~irisson/upload/
Reply all
Reply to author
Forward
0 new messages