Creating a facet box plot
With faceting tools at hand, we will now give the car::Salaries
data frame a better look. There are many aspects of this particular data set that stood out in the analysis made at previous chapters. In this recipe, a facet box plot will be crafted. We shall use ranks
 and discipline
variables to create facets. Variables sex
 and salary
 are going to fit respectively the x and y axes.
Variable discipline
is assigned with A
for theoretical departments and B
for applied ones, so this recipe will also teach how to relabel these in order to make it intuitive.
How to do it...
Let us now create a facet box plot:
- Store data into a new object and factor
discipline
properly:
> library(car) > data_box <- Salaries > data_box$discipline <- factor(data_box$discipline, labels = c('theoretical','applied'))
- Craft a box plot and call
facet_grid()
:
> library(ggplot2) > boxplot <- ggplot(data = data_box) + geom_boxplot(aes( x = sex, y = salary), position = 'identity...