為圖形加入標籤
如同影片所說,你要把上一題的圖形加上標題、副標題與註記,同時為座標軸取有意義的名稱。你會使用 labs() 函式來完成這些事——試著在主控台輸入 ?labs 查看可用的選項。
本練習屬於課程
在 Tidyverse 中以資料溝通
練習說明
- 使用
labs()函式為圖形加上註解。 - 在
labs的呼叫中指定正確的引數。- 使用
?labs開啟說明,看看labs()需要哪些引數。 - 大多數註解該填入哪些引數應該不難判斷,而
"The more people work, the less compensation they seem to receive"應作為圖形的標題。
- 使用
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the plot
ggplot(plot_data) +
geom_point(aes(x = working_hours, y = hourly_compensation)) +
# Add labels
___(
___ = "Working hours per week",
___ = "Hourly compensation",
___ = "The more people work, the less compensation they seem to receive",
___ = "Working hours and hourly compensation in European countries, 2006",
___ = "Data source: ILO, 2017"
)