ธีมจากศูนย์

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

Rick Scavetta

Founder, Scavetta Academy

เลเยอร์ themes

  • หมึกที่ไม่ใช่ข้อมูลทั้งหมด
  • องค์ประกอบภาพที่ไม่ได้เป็นส่วนหนึ่งของข้อมูล
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

เลเยอร์ themes

  • หมึกที่ไม่ใช่ข้อมูลทั้งหมด
  • องค์ประกอบภาพที่ไม่ได้เป็นส่วนหนึ่งของข้อมูล

สามประเภท

ประเภท
text
line
rectangle
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

เลเยอร์ themes

  • หมึกที่ไม่ใช่ข้อมูลทั้งหมด
  • องค์ประกอบภาพที่ไม่ได้เป็นส่วนหนึ่งของข้อมูล

สามประเภท

ประเภท ปรับแต่งด้วย
text element_text()
line element_line()
rectangle element_rect()
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

กราฟเริ่มต้น...

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6)

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

องค์ประกอบ text


text
  axis.title 
    axis.title.x
      axis.title.x.top
      axis.title.x.bottom 
    axis.title.y
      axis.title.y.left
      axis.title.y.right 
  title 
    legend.title 
    plot.title
    plot.subtitle 
    plot.caption 
    plot.tag
  axis.text 
    axis.text.x 
      axis.text.x.top
      axis.text.x.bottom 
    axis.text.y
      axis.text.y.left
      axis.text.y.right
  legend.text
  strip.text
    strip.text.x
    strip.text.y
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

องค์ประกอบ text

theme(
text, 
  axis.title, 
    axis.title.x,
      axis.title.x.top, 
      axis.title.x.bottom, 
    axis.title.y, 
      axis.title.y.left,
      axis.title.y.right, 
  title, 
    legend.title, 
    plot.title,
    plot.subtitle, 
    plot.caption, 
    plot.tag, 
  axis.text, 
    axis.text.x, 
      axis.text.x.top,
      axis.text.x.bottom, 
    axis.text.y, 
      axis.text.y.left, 
      axis.text.y.right,
  legend.text,
  strip.text, 
    strip.text.x, 
    strip.text.y)
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ปรับแต่งองค์ประกอบ theme

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6) +
  theme(axis.title = element_text(color = "blue"))

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

กราฟเริ่มต้น...

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6)

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

องค์ประกอบ line

theme(
line,
  axis.ticks,
    axis.ticks.x, 
      axis.ticks.x.top,
      axis.ticks.x.bottom,
    axis.ticks.y,
      axis.ticks.y.left, 
      axis.ticks.y.right,
    axis.line,
      axis.line.x, 
        axis.line.x.top,
        axis.line.x.bottom, 
      axis.line.y,
        axis.line.y.left, 
        axis.line.y.right, 
  panel.grid,
    panel.grid.major, 
      panel.grid.major.x, 
      panel.grid.major.y, 
    panel.grid.minor,
      panel.grid.minor.x,
      panel.grid.minor.y)
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

กราฟเริ่มต้น...

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6)

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

องค์ประกอบ rect

theme(
rect,
  legend.background, 
  legend.key,
  legend.box.background, 
  panel.background,
  panel.border,
  plot.background, 
  strip.background, 
    strip.background.x, 
    strip.background.y)
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

การตั้งชื่อแบบลำดับชั้นสะท้อนกฎการสืบทอด

e.g. Text

text
  axis.title 
    axis.title.x
      axis.title.x.top
      axis.title.x.bottom 
    axis.title.y
      axis.title.y.left
      axis.title.y.right 

e.g. Lines

line
  axis.ticks
    axis.ticks.x 
      axis.ticks.x.top
      axis.ticks.x.bottom
    axis.ticks.y
      axis.ticks.y.left,
      axis.ticks.y.right
    axis.line
      axis.line.x 
        axis.line.x.top
        axis.line.x.bottom
      axis.line.y
        axis.line.y.left 
        axis.line.y.right
การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

element_blank()

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6) + 
  theme(line = element_blank(),
        rect = element_blank(),
        text = element_blank())

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

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

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

Preparing Video For Download...