ファセット層

ggplot2 中級データ可視化

Rick Scavetta

Founder, Scavetta Academy

ファセット

  • 単純だが有用
  • スモールマルチプルの概念
    • Edward Tufte が普及
    • The Visual Display of Quantitative Information(1983)
ggplot2 中級データ可視化

ggplot2 中級データ可視化

ggplot2 中級データ可視化

iris.wide

p <- ggplot(iris.wide, aes(x = Length, 
                           y = Width, 
                           ccolorol = Part)) +
  geom_jitter(alpha = 0.7) +
  scale_color_brewer(palette = "Set1") +
  coord_fixed()

p

ggplot2 中級データ可視化

iris.wide と facet_grid()

p <- ggplot(iris.wide, aes(x = Length, y = Width, color = Part)) +
  geom_jitter(alpha = 0.7) +
  scale_color_brewer(palette = "Set1") +
  coord_fixed()
p + facet_grid(cols = vars(Species))

ggplot2 中級データ可視化

数式表記

p <- ggplot(iris.wide, aes(x = Length, y = Width, color = Part)) +
  geom_jitter(alpha = 0.7) +
  scale_color_brewer(palette = "Set1") +
  coord_fixed()
p + facet_grid(. ~ Species)

ggplot2 中級データ可視化

iris.wide2

ggplot(iris.wide2, aes(x = Part, y = setosa, color = Measure)) +
  geom_jitter()
ggplot(iris.wide2, aes(x = Part, y = versicolor, color = Measure)) +
  geom_jitter()  
ggplot(iris.wide2, aes(x = Part, y = virginica, color = Measure)) +
  geom_jitter()

ggplot2 中級データ可視化

iris.tidy

ggplot(iris.tidy, aes(x = Measure, y = Value, color = Part)) +
  geom_jitter() +
  facet_grid(cols = vars(Species))

ggplot2 中級データ可視化

iris.tidy の誤ったファセット設定:

ggplot(iris.tidy, aes(x = Measure, 
                      y = Value, 
                      color = Part)) +
  geom_jitter() +
  facet_grid(rows = vars(Species))

ggplot2 中級データ可視化

その他のオプション

  • 行・列で分割可能
ggplot2 中級データ可視化

練習しましょう!

ggplot2 中級データ可視化

Preparing Video For Download...