カスタム ggplot2 テーマ

Tidyverseによるデータコミュニケーション

Timo Grossenbacher

Data Journalist

カスタム外観のメリット

Tidyverseによるデータコミュニケーション

theme() 関数

ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +
  theme(
    text = element_text(
      family = "Bookman",
      color = "gray25")
  )

Tidyverseによるデータコミュニケーション

ggplot2 のデフォルトテーマ

ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +

  theme_classic()

Tidyverseによるデータコミュニケーション

theme() 呼び出しの連結

ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +

  theme_classic() +
  theme(
    text = element_text(
      family = "Bookman",
      color = "gray25")
  )

Tidyverseによるデータコミュニケーション

テーマ設定オプション

?theme

axis.title
軸のラベル(element_text;text から継承)

axis.title.x
x 軸ラベル(element_text;axis.title から継承)

axis.title.x.top
上部 x 軸ラベル(element_text;axis.title.x から継承)

axis.title.x.bottom
下部 x 軸ラベル(element_text;axis.title.x から継承)

Tidyverseによるデータコミュニケーション

element_* 関数ファミリー

element_text()
element_rect()
element_line()
element_blank()
ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +
  theme(
    text = element_blank()
  )

Tidyverseによるデータコミュニケーション

テーマを試してみましょう!

Tidyverseによるデータコミュニケーション

Preparing Video For Download...