Graphics Reference
In-Depth Information
library(MASS) # For the data set
ggplot(birthwt, aes(x = factor(race), y = bwt)) + geom_boxplot() +
stat_summary(fun.y = "mean" , geom = "point" , shape = 23 , size = 3 , fill = "white" )
Figure 6-20. Mean markers on a box plot
Discussion
The horizontal line in the middle of a box plot displays the median, not the mean. For data that
is normally distributed, the median and mean will be about the same, but for skewed data these
values will differ.
Making a Violin Plot
Problem
You want to make a violin plot to compare density estimates of different groups.
Solution
Use geom_violin() ( Figure 6-21 ):
library(gcookbook) # For the data set
# Base plot
p <- ggplot(heightweight, aes(x = sex, y = heightIn))
p + geom_violin()
Search WWH ::




Custom Search