เพิ่ม facets ลงในกราฟ
ในแบบฝึกหัดนี้ จะใช้ facet_grid() เพื่อเพิ่ม facets แนวนอนสำหรับปี 1996 และ 2006 ตามที่อธิบายไว้ในวิดีโอ
เมื่อใช้ facet_grid() แนวทางที่ดีคือระบุการจัดเรียงกราฟด้วย argument แบบตั้งชื่อ ได้แก่ rows = ... หรือ cols = ... วิธีนี้ช่วยลดความสับสน เนื่องจากฟังก์ชัน facet_grid() รับ argument อื่นอีกหลายตัว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสื่อสารด้วยข้อมูลใน Tidyverse
คำแนะนำการฝึกหัด
- ใช้
facet_grid()พร้อม argument ที่เหมาะสม เพื่อสร้าง scatter plot แยกสองกราฟที่จัดเรียงในแนวนอน - กราฟทางซ้ายควรแสดงข้อมูลของปี 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