
上QQ阅读APP看书,第一时间看更新
How to do it...
Let's get started with the recipe:
- Draw the base aesthetics under an object:
> library(ggplot2)
> base <-ggplot(car::Salaries,
aes(x = rank, y = salary))
- Call geom_violin() to draw a simple violin plot:
> base + geom_violin()
Following figure is the output obtained by the preceding code:

Figure 3.9 Simple violin plot.
- To enhance it, you can fill the inside and add a box plot:
> base + geom_violin(fill = 'steelblue1') +
geom_boxplot(outlier.shape = NA, width = .1)
Following figure demonstrates the result:

Figure 3.10: Violins and boxes combined
Keep going on for explanations!