テーマを一から作る

ggplot2 で始めるデータ可視化入門

Rick Scavetta

Founder, Scavetta Academy

テーマ層

  • データ以外のインクすべて
  • データ本体でない視覚要素
ggplot2 で始めるデータ可視化入門

テーマ層

  • データ以外のインクすべて
  • データ本体でない視覚要素

【3種類】

種類
テキスト
矩形
ggplot2 で始めるデータ可視化入門

テーマ層

  • データ以外のインクすべて
  • データ本体でない視覚要素

【3種類】

種類 変更に使う関数
テキスト element_text()
element_line()
矩形 element_rect()
ggplot2 で始めるデータ可視化入門

初期プロット...

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

ggplot2 で始めるデータ可視化入門

テキスト要素


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(
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 で始めるデータ可視化入門

テーマ要素の調整

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 で始めるデータ可視化入門

線要素

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 で始めるデータ可視化入門

矩形要素

theme(
rect,
  legend.background, 
  legend.key,
  legend.box.background, 
  panel.background,
  panel.border,
  plot.background, 
  strip.background, 
    strip.background.x, 
    strip.background.y)
ggplot2 で始めるデータ可視化入門

階層名は継承ルールを反映

例: テキスト

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 

例: 線

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...