CommencerCommencer gratuitement

Add facets to the plot

Here, you'll leverage facet_grid() to add horizontal facets for 1996 and 2006 each, as detailed in the video.

When using facet_grid(), it is good practice to specify the arrangement of plots with a named argument: rows = ... or cols = .... This helps to avoid confusion since the facet_grid() function takes many other arguments.

Cet exercice fait partie du cours

Communicating with Data in the Tidyverse

Afficher le cours

Instructions

  • Use facet_grid() with the right argument to generate two separate scatter plots that are arranged horizontally.
  • The left plot should show the data for the year 1996 while the year 2006 should be shown on the right side.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Again, you save the plot object into a variable so you can save typing later on
ilo_plot <- ggplot(ilo_data, aes(x = working_hours, y = hourly_compensation)) +
  geom_point() +
   labs(
    x = "Working hours per week",
    y = "Hourly compensation",
    title = "The more people work, the less compensation they seem to receive",
    subtitle = "Working hours and hourly compensation in European countries, 2006",
    caption = "Data source: ILO, 2017"
  ) +
  # Add facets here
  ___(___)
 
ilo_plot
Modifier et exécuter le code