เพิ่มสีให้กับ Scatter Plot
ในบทเรียนนี้ได้เรียนรู้วิธีใช้ aesthetic สำหรับสี ซึ่งช่วยแสดงให้เห็นว่าแต่ละจุดใน scatter plot นั้นอยู่ในทวีปใด
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Introduction to the Tidyverse
คำแนะนำการฝึกหัด
- สร้าง scatter plot โดยให้แกน x แสดงจำนวนประชากร (
pop) แกน y แสดงอายุขัยเฉลี่ย (lifeExp) และใช้สีของจุดแสดงทวีป (continent) จากนั้นปรับแกน x ให้เป็น log scale
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
library(gapminder)
library(dplyr)
library(ggplot2)
gapminder_1952 <- gapminder %>%
filter(year == 1952)
# Scatter plot comparing pop and lifeExp, with color representing continent