De coördinatenlaag

Gevorderde datavisualisatie met ggplot2

Rick Scavetta

Founder, Scavetta Academy

Coördinatenlaag

  • Bepaalt de afmetingen van de plot
  • coord_
    • bijv. coord_cartesian()
Gevorderde datavisualisatie met ggplot2

Inzoomen

  • coord_cartesian(xlim = ...)
  • scale_x_continuous(limits = ...)
  • xlim(...)
Gevorderde datavisualisatie met ggplot2

Originele plot

iris.smooth <- ggplot(
  iris, 
  aes(x = Sepal.Length, 
      y = Sepal.Width, 
      color = Species)
  ) + 
  geom_point(alpha = 0.7) +
  geom_smooth()

iris.smooth 

Gevorderde datavisualisatie met ggplot2

scale_x_continuous()

iris.smooth + 
  scale_x_continuous(limits = c(4.5, 5.5))
Removed 95 rows containing non-finite values 
(stat_smooth).
Removed 95 rows containing missing values 
(geom_point).

Gevorderde datavisualisatie met ggplot2

scale_x_continuous()

Originele plot

Inzoomen met scale_x_continuous()

Deel van de originele data wordt weggefilterd!

Gevorderde datavisualisatie met ggplot2

xlim()

iris.smooth +
  xlim(c(4.5, 5.5))
Removed 95 rows containing non-finite values 
(stat_smooth).
Removed 95 rows containing missing values 
(geom_point).

Gevorderde datavisualisatie met ggplot2

coord_cartesian()

iris.smooth +
  coord_cartesian(xlim = c(4.5, 5.5))

Gevorderde datavisualisatie met ggplot2

Aspect ratio

  • Hoogte-breedteverhouding
  • Pas op voor misleiding!
  • Geen universele standaard
  • Gebruik vaak 1:1 als schalen gelijk zijn
Gevorderde datavisualisatie met ggplot2

Zonnevlekken

library(zoo)
sunspots.m <- data.frame(
    year = index(sunspot.month),
    value = reshape2::melt(sunspot.month)$value)
)

ggplot(sunspots.m, aes(x = year, y = value)) +
  geom_line() +
  coord_fixed() # default to 1:1 aspect ratio

Gevorderde datavisualisatie met ggplot2

Zonnevlekken

ggplot(sunspots.m, aes(x = year, y = value)) +
  geom_line() +
  coord_fixed(0.055)

Gevorderde datavisualisatie met ggplot2

Laten we oefenen!

Gevorderde datavisualisatie met ggplot2

Preparing Video For Download...