เลเยอร์ของ ggplot2

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

Rick Scavetta

Founder, Scavetta Academy

แพ็กเกจ ggplot2

  • ไวยากรณ์ของกราฟิกที่ใช้งานใน R
  • แนวคิดหลัก 2 ประการ:
    1. องค์ประกอบเชิงไวยากรณ์แบบเลเยอร์
    2. การแมป Aesthetic
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ข้อมูล

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ชุดข้อมูล Iris

1 Fisher, R. A. (1936) The use of multiple measurements in taxonomic problems. Annals of Eugenics, 7, Part II, 179–188. 2 Anderson, Edgar (1935). The irises of the Gaspe Peninsula, Bulletin of the American Iris Society, 59, 2–5.
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ชุดข้อมูล Iris

iris
    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1            5.1         3.5          1.4         0.2     setosa
2            4.9         3.0          1.4         0.2     setosa
3            4.7         3.2          1.3         0.2     setosa
...
50           5.0         3.3          1.4         0.2     setosa
51           7.0         3.2          4.7         1.4 versicolor
52           6.4         3.2          4.5         1.5 versicolor
53           6.9         3.1          4.9         1.5 versicolor
...
100          5.7         2.8          4.1         1.3 versicolor
101          6.3         3.3          6.0         2.5  virginica
102          5.8         2.7          5.1         1.9  virginica
103          7.1         3.0          5.9         2.1  virginica
...
150          5.9         3.0          5.1         1.8  virginica
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

Aesthetics

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

Aesthetics ของ Iris

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

เรขาคณิต (Geometries)

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

เรขาคณิตของ Iris

g <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_jitter()
g

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ธีม (Themes)

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ธีมของ Iris

g <- g +
  labs(x = "Sepal Length (cm)", y = "Sepal Width (cm)") +
  theme_classic()
g

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

มาฝึกกันเถอะ!

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

Preparing Video For Download...