Creating facet plots for histograms
As with scatterplots, we can create facet plots for histograms. This technique is useful when we have one or more categorical variables and wish to obtain histograms for each level or combination of levels. Let's create a histogram facet plot of weight before treatment for each level of treatment. First, we turn TREATMENT
into a factor. To create facet plots across the levels of a categorical variable, first turn the variable into a factor using the following syntax:
TRC <- factor(TREATMENT)
Now, let's create the facet plot using the syntax facets = TREATMENT ~ .
qplot(WEIGHT_1, data = T, geom = "histogram", binwidth = 5, xlab = "WEIGHT", ylab = "FREQUENCY", fill = I("red"), facets = TREATMENT ~ .)
The facet plot is shown as follows:
We now have a histogram for each level of TREATMENT
. Facet plots provide additional detail about the variability of the critical variables.