Aggiungi i facet al grafico
Qui userai facet_grid() per aggiungere facet orizzontali per il 1996 e il 2006, come mostrato nel video.
Quando usi facet_grid(), è buona norma specificare la disposizione dei grafici con un argomento con nome: rows = ... oppure cols = .... Questo aiuta a evitare confusione, dato che la funzione facet_grid() accetta molti altri argomenti.
Questo esercizio fa parte del corso
Comunicare con i dati nel Tidyverse
Istruzioni dell'esercizio
- Usa
facet_grid()con l'argomento corretto per generare due scatter plot separati disposti orizzontalmente. - Il grafico di sinistra deve mostrare i dati per l'anno 1996, mentre quello di destra deve mostrare l'anno 2006.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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