座標 vs. 尺度

ggplot2 中級資料視覺化

Rick Scavetta

Founder, Scavetta Academy

繪製原始資料

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

偏斜資料

ggplot2 中級資料視覺化

轉換原始資料

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

轉換後的原始值

ggplot2 中級資料視覺化

加入對數刻度標記

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

轉換後的原始值(含刻度標記)

ggplot2 中級資料視覺化

使用 scale_*_log10()

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

尺度轉換

ggplot2 中級資料視覺化

比較直接轉換與 scale_*_log10() 輸出

轉換後的原始值

尺度轉換

ggplot2 中級資料視覺化

使用 coord_trans()

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

座標轉換

ggplot2 中級資料視覺化

比較 scale_*_log10() 與 coord_trans() 輸出

座標轉換

尺度轉換

ggplot2 中級資料視覺化

調整標籤

重新標示的座標

重新標示的尺度

ggplot2 中級資料視覺化

開始做練習

ggplot2 中級資料視覺化

Preparing Video For Download...