시작하기무료로 시작하기

플롯에 패싯 추가하기

여기서는 영상에서 설명한 대로, facet_grid()를 사용해 1996년과 2006년에 해당하는 가로 패싯을 각각 추가해 보겠습니다.

facet_grid()를 사용할 때는 rows = ... 또는 cols = ...처럼 이름 있는 인수로 플롯 배열을 지정하는 것이 좋아요. facet_grid()는 인수가 많기 때문에, 이렇게 하면 혼동을 줄일 수 있어요.

이 연습은 강의의 일부입니다

Tidyverse로 데이터 소통하기

강의 보기

연습 안내

  • facet_grid()에 올바른 인수를 사용해 가로로 배열된 두 개의 산점도를 만드세요.
  • 왼쪽 플롯에는 1996년 데이터를, 오른쪽 플롯에는 2006년 데이터를 표시하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# 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
코드 편집 및 실행