This section shows you how to create a faceted bar graph:
- Coerce the Titanic table to the data frame type:
> data_titanic <- as.data.frame(Titanic)
- Load ggplot2, design a bar graph, and add the facets using face_grid() function:
> library(ggplot2)> bar <- ggplot(data_titanic, aes(x = Survived)) + geom_bar(aes(fill = Survived, weight = Freq)) + facet_grid(Sex ~ Age)
- Check the result by calling the object storing the plot:
Output might look much like the following illustration (Figure 7.1):
Figure 7.1 - Faceted bar graph, Titanic survivals based on age range and gender.
- Also, the plotly package could be called ...