開始使用免費開始

為圖形加入分面

在這裡,你要使用 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
編輯並執行程式碼