
上QQ阅读APP看书,第一时间看更新
How it works...
Now let's combine box and dot plots:
- Combine geom_boxplot() and geom_dotplot() to reach the desired effect:
> library(ggplot2) ; library(car)
> dot1 <- ggplot(Salaries, aes( x = rank, y = salary))
> dot1 + geom_boxplot(outlier.size = 0) +
geom_dotplot(binaxis = 'y',
dotsize = .3,
stackdir = 'center',
fill = 'red', alpha = .5)
Following image (Figure 3.6) shows boxes displayed beneath the dots:

Figure 3.6: Dot and box geometry combined.
- plotly can achieve similar result by combining parameters type = 'box' and boxpoints = 'all':
> library(plotly)
> box2 <- plot_ly(data = Salaries, x = ~rank,
y = ~salary, type = 'box',
boxpoints = 'all',
marker = list(color = 'red',
opacity = .2))
> box2
Check the result in the following graphic (Figure 3.7):

Figure 3.7: plotly's dot and box combination.