17 ggplot2
17.2 Resources
- ggplot2 book
- Claus Wilke’s course Data Visualization in R, book Fundamentals of Data Visualization
- What makes bad figures bad
17.3 Facets
Facet wrap using categorical columns:
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~cut)
![](_main_files/figure-html/unnamed-chunk-17-1.png)
Facet wrap using automatically binned values:
“What if I look at four separate chunks of the data, with approximately the same number of points”
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~ cut_number(carat, 4))
![](_main_files/figure-html/unnamed-chunk-18-1.png)
“What if I look at four separate chunks of the data, with the equal ranges in each group?”
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~ cut_interval(carat, 4))
![](_main_files/figure-html/unnamed-chunk-19-1.png)
“What if I look at four separate chunks of the data, with a specific width of values in each group?”
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~ cut_width(carat, 0.5))
![](_main_files/figure-html/unnamed-chunk-20-1.png)