LoginSignup
4
9

More than 3 years have passed since last update.

【R】ggplot2全テーマ一覧

Last updated at Posted at 2020-07-12

モチベーション

ggplot2でサッと作図したいときに毎回調べている気がするので備忘録として。

手法

「ggplot2::theme_○○」の全10テーマ(+デフォルト)でirisから散布図を作図してみます。
irisは3種のアヤメ(setosa, versicolor, virginica)について、がく(sepal)と花弁(petal)の幅・長さを測定したデータです。

rm(list = ls())

#環境、使用パッケージ・iris読み込み
sessionInfo()
# R version 4.0.2 (2020-06-22)
# Platform: x86_64-apple-darwin17.0 (64-bit)
# Running under: macOS Mojave 10.14.1

packageVersion("ggplot2")
#[1] ‘3.3.2’

library(ggplot2)
library(gridExtra)
data(iris)

結果

p1 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("bw") + theme_bw() + 
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p2 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("classic") + theme_classic() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p3 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("dark") + theme_dark() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p4 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("gray") + theme_gray() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
ggsave("ggplot2_p1234.png", gridExtra::grid.arrange(p1, p2, p3, p4), width = 9)  

ggplot2_p1234.png

p5 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("grey") + theme_grey() + 
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p6 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("light") + theme_light() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p7 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("linedraw") + theme_linedraw() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p8 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("minimal") + theme_minimal() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
ggsave("ggplot2_p5678.png", gridExtra::grid.arrange(p5, p6, p7, p8), width = 9)  

ggplot2_p5678.png

p9 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("test") + theme_test() + 
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p10 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("void") + theme_void() +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
p11 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
        geom_point() + ggtitle("default") +
        theme(plot.title = element_text(hjust = 0.5, size = 18))
ggsave("ggplot2_p91011.png", gridExtra::grid.arrange(p9, p10, p11, ncol = 2), width = 9)

ggplot2_p91011.png

感想

grayとgreyってアメリカ英語かイギリス英語かの違いで内容自体は同じなんですかね(違いが分からない)?この2つがggplot2のデフォルトのテーマっぽいですね。
darkやデフォルト(gray・grey)のデザイン性は高いですが、レポートや論文にはすっきりとしたclassicあたりが良さそうです。

4
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
9