Coordinates vs. scales

Visualizzazione dei dati intermedia con ggplot2

Rick Scavetta

Founder, Scavetta Academy

Plot the raw data

ggplot(msleep, aes(bodywt, y = 1)) +
  geom_jitter() +
  scale_x_continuous(limits = c(0, 7000), 
                     breaks = seq(0, 7000, 1000))

Skewed data

Visualizzazione dei dati intermedia con ggplot2

Transform the raw data

ggplot(msleep, aes(log10(bodywt), y = 1)) +
  geom_jitter() +
  scale_x_continuous(limits = c(-3, 4),
                     breaks = -3:4)

Trans raw values

Visualizzazione dei dati intermedia con ggplot2

Add logtick annotation

ggplot(msleep, aes(log10(bodywt), y = 1)) +
  geom_jitter() +
  scale_x_continuous(limits = c(-3, 4),
                     breaks = -3:4) +
  annotation_logticks(sides = "b")

Trans raw values, with tick marks

Visualizzazione dei dati intermedia con ggplot2

Use scale_*_log10()

ggplot(msleep, aes(bodywt, y = 1)) +
  geom_jitter() +
  scale_x_log10(limits = c(1e-03, 1e+04))

scale trans

Visualizzazione dei dati intermedia con ggplot2

Compare direct transform and scale_*_log10() output

Trans raw values

scale trans

Visualizzazione dei dati intermedia con ggplot2

Use coord_trans()

ggplot(msleep, aes(bodywt, y = 1)) +
  geom_jitter() +
  coord_trans(x = "log10") 

coord trans

Visualizzazione dei dati intermedia con ggplot2

Compare scale_*_log10() and coord_trans() output

coord trans

scale trans

Visualizzazione dei dati intermedia con ggplot2

Adjusting labels

coord relabeled

scale relabeled

Visualizzazione dei dati intermedia con ggplot2

Time for exercises

Visualizzazione dei dati intermedia con ggplot2

Preparing Video For Download...