修改主題元素
許多圖表元素都有多種可設定的屬性。例如,圖中的線條元素(如座標軸與網格線)有顏色、粗細(size)與線型(實線、虛線或點線)。若要設定線條樣式,請使用 element_line()。例如,想把座標軸的線改成紅色虛線,可以這樣寫:
p + theme(axis.line = element_line(color = "red", linetype = "dashed"))
同樣地,element_rect() 用來調整矩形,element_text() 用來調整文字。你也可以用 element_blank() 來移除某個圖表元素。
plt_prop_unemployed_over_time 已可使用。
本練習屬於課程
ggplot2 資料視覺化入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
plt_prop_unemployed_over_time +
theme(
# For all rectangles, set the fill color to grey92
___ = ___(___ = ___),
# For the legend key, turn off the outline
___
)