美的要素の調整

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

Rick Scavetta

Founder, Scavetta Academy

位置指定(position)

重なりの調整

  • identity
  • dodge
  • stack
  • fill
  • jitter
  • jitterdodge
  • nudge
ggplot2 で始めるデータ可視化入門

position = "identity"(既定)

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

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

position = "identity"(既定)

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "identity")

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

position = "jitter"

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "jitter")

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

position_jitter()

posn_j <- position_jitter(0.1)

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 col = Species)) +
  geom_point(position = posn_j)

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

position_jitter()

posn_j <- position_jitter(0.1, 
                          seed = 136)

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = posn_j)
  • 位置の引数を設定
  • 複数プロット・レイヤーで一貫性

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

スケール関数

  • scale_x_*()
  • scale_y_*()
  • scale_color_*()
    • scale_colour_*() も可
  • scale_fill_*()
  • scale_shape_*()
  • scale_linetype_*()
  • scale_size_*()
ggplot2 で始めるデータ可視化入門

スケール関数

  • scale_x_continuous()
  • scale_y_*()
  • scale_color_discrete()
    • あるいは scale_colour_*()
  • scale_fill_*()
  • scale_shape_*()
  • scale_linetype_*()
  • scale_size_*()
ggplot2 で始めるデータ可視化入門

scale_*_*()

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "jitter") +
  scale_x_continuous("Sepal Length") +
  scale_color_discrete("Species")

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

limits 引数

ggplot(iris, aes(x = Sepal.Length, 
                  y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "jitter") +
  scale_x_continuous("Sepal Length", 
                     limits = c(2,8)) +
  scale_color_discrete("Species")

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

breaks 引数

ggplot(iris, aes(x = Sepal.Length, 
                  y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "jitter") +
  scale_x_continuous("Sepal Length", 
                     limits = c(2, 8), 
                     breaks = seq(2, 8, 3)) +
  scale_color_discrete("Species")

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

expand 引数

ggplot(iris, aes(x = Sepal.Length, 
                  y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "jitter") +
  scale_x_continuous("Sepal Length", 
                     limits = c(2, 8), 
                     breaks = seq(2, 8, 3),
                     expand = c(0, 0)) +
  scale_color_discrete("Species")

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

labels 引数

ggplot(iris, aes(x = Sepal.Length, 
                  y = Sepal.Width, 
                 color = Species)) + 
  geom_point(position = "jitter") +
  scale_x_continuous("Sepal Length", 
                     limits = c(2, 8), 
                     breaks = seq(2, 8, 3),
                     expand = c(0, 0), 
                     labels = c("Setosa", 
                               "Versicolor", 
                               "Virginica")) +
  scale_color_discrete("Species")

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

labs()

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) +
  geom_point(position = "jitter") +
  labs(x = "Sepal Length", 
       y = "Sepal Width", 
       color = "Species")

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

試してみましょう!

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

Preparing Video For Download...