เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

แสดงความแตกต่างด้วยกราฟ: Batman และ Star Wars

ในแบบฝึกหัดที่แล้ว คุณได้สร้าง colors_joined ขึ้นมาแล้ว คราวนี้จะสร้าง bar plot โดยมีแท่งหนึ่งแท่งสำหรับแต่ละสี (name) เพื่อแสดงความแตกต่างของสัดส่วน

เนื่องจาก factors และการแสดงภาพข้อมูลอยู่นอกเหนือขอบเขตของคอร์สนี้ เราจึงได้จัดเตรียมโค้ดบางส่วนไว้ให้แล้ว โค้ดด้านล่างนี้คือส่วนที่สร้างตาราง colors_joined ซึ่งจะใช้ในวิดีโอ

colors_joined <- batman_colors %>%
  full_join(star_wars_colors, by = "color_id", suffix = c("_batman", "_star_wars")) %>%
  replace_na(list(total_batman = 0, total_star_wars = 0)) %>%
  inner_join(colors, by = c("color_id" = "id")) %>%
  mutate(difference = fraction_batman - fraction_star_wars,
         total = total_batman + total_star_wars) %>%
  filter(total >= 200) %>%
  mutate(name = fct_reorder(name, difference)) 

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การ Join ข้อมูลด้วย dplyr

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้าง bar plot โดยใช้ตาราง colors_joined เพื่อแสดงสีที่โดดเด่นที่สุดในธีม Batman และ Star Wars โดยให้แท่งกราฟแต่ละแท่งมีสีตามค่า name

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Create a bar plot using colors_joined and the name and difference columns
ggplot(___, aes(___, ___, fill = ___)) +
  geom_col() +
  coord_flip() +
  scale_fill_manual(values = color_palette, guide = "none") +
  labs(y = "Difference: Batman - Star Wars")
แก้ไขและรันโค้ด