1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Data Visualization with ggplot2

Connected

Exercise

Formula notation

As well as the vars() notation for specifying which variables should be used to split the dataset into facets, there is also a traditional formula notation. The three cases are shown in the table.

| Modern notation                            | Formula notation  |
|--------------------------------------------|-------------------|
| facet_grid(rows = vars(A))                 | facet_grid(A ~ .) |
| facet_grid(cols = vars(B))                 | facet_grid(. ~ B) |
| facet_grid(rows = vars(A), cols = vars(B)) | facet_grid(A ~ B) |

mpg_by_wt is available again. Rework the previous plots, this time using formula notation.

Instructions 1/3

undefined XP
  • 1
    • Facet the plot in a grid, with each am value in its own row.
  • 2
    • Facet the plot in a grid, with each cyl value in its own column.
  • 3
    • Facet the plot in a grid, with each am value in its own row and each cyl value in its own column.