翻轉座標軸 I
「翻轉」座標軸是指把對應到 x 與 y 美學屬性的變數互換。我們可以直接更改 aes() 裡的映射,也可以使用圖層函式 coord_flip()。
使用這個函式有兩個理由:
- 想把原本垂直的幾何物件改成水平,或
- 你已經串起一長串繪圖函式,想要翻轉圖形但不想重寫所有指令。
本練習屬於課程
ggplot2 中級資料視覺化
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot fcyl bars, filled by fam
ggplot(mtcars, aes(___, fill = ___)) +
# Place bars side by side
geom_bar(position = ___)