放大檢視
在影片中,你看到使用座標圖層進行放大的不同方法。在這個練習中,我們要比較透過調整尺度與調整座標來放大的差異。
最大的不同在於:尺度函式會變動底層資料集,影響到由計算型幾何圖層(例如直方圖或平滑趨勢線)所做的計算;而座標函式不會更動資料集本身。
我們提供了一個使用 mtcars 的散佈圖,並加入 LOESS 平滑趨勢線。請先看一下原始圖,再進行更新。
本練習屬於課程
ggplot2 中級資料視覺化
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Run the code, view the plot, then update it
ggplot(mtcars, aes(x = wt, y = hp, color = fam)) +
geom_point() +
geom_smooth()
# Add a continuous x scale from 3 to 6