Adding notches and jitters to box plots
A very useful feature/trick regarding box plots are notches. They are easily achieved by ggplot2
; however, when the book was written, this was neither true for ggvis
nor plotly
. It adds little more information about distribution. Notches usually indicate the 95 percent confidence interval around the median, proven to be very useful in suggesting skews and making simple comparison between groups.
In addition to teaching how we can add notches to box plots, this recipe will also demonstrate how to apply jitter the outliers. Jittering is a feasible response to over-plotting that may come with outliers.
Getting ready
Having the car
package is a requirement here:
> if( !require(car)){ install.packages('car')}
Now that we are locked and loaded, let's code.
How to do it...
We proceed as follows to add notches and jitters to box plots:
- Load the packages and use
boxplot.stats()
to separate the outliers:
> library(ggplot2) ; library(car) > out_data <- Salaries...