Mengubah Estetika

Pengantar Visualisasi Data dengan ggplot2

Rick Scavetta

Founder, Scavetta Academy

Posisi

Penyesuaian tumpang tindih

  • identity
  • dodge
  • stack
  • fill
  • jitter
  • jitterdodge
  • nudge
Pengantar Visualisasi Data dengan ggplot2

position = "identity" (bawaan)

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

Pengantar Visualisasi Data dengan ggplot2

position = "identity" (bawaan)

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

Pengantar Visualisasi Data dengan ggplot2

position = "jitter"

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

Pengantar Visualisasi Data dengan 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)

Pengantar Visualisasi Data dengan 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)
  • Atur argumen posisi
  • Konsisten di plot & layer

Pengantar Visualisasi Data dengan ggplot2

Fungsi skala

  • scale_x_*()
  • scale_y_*()
  • scale_color_*()
    • Juga scale_colour_*()
  • scale_fill_*()
  • scale_shape_*()
  • scale_linetype_*()
  • scale_size_*()
Pengantar Visualisasi Data dengan ggplot2

Fungsi skala

  • scale_x_continuous()
  • scale_y_*()
  • scale_color_discrete()
    • Alternatif: scale_colour_*()
  • scale_fill_*()
  • scale_shape_*()
  • scale_linetype_*()
  • scale_size_*()
Pengantar Visualisasi Data dengan 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")

Pengantar Visualisasi Data dengan ggplot2

Argumen 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")

Pengantar Visualisasi Data dengan ggplot2

Argumen 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")

Pengantar Visualisasi Data dengan ggplot2

Argumen 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")

Pengantar Visualisasi Data dengan ggplot2

Argumen 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")

Pengantar Visualisasi Data dengan 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")

Pengantar Visualisasi Data dengan ggplot2

Ayo berlatih!

Pengantar Visualisasi Data dengan ggplot2

Preparing Video For Download...