《R數(shù)據(jù)可視化手冊》學(xué)習(xí)筆記9---控制圖形整體輸出(1)設(shè)置圖形的標(biāo)題

寫在前面。

在本文中將討論如何控制 ggplot2 圖形的整體外觀,例如字體背景顏色等問題。

數(shù)據(jù)所映射的圖形元素不同,主題系統(tǒng)為控制非數(shù)據(jù)元素的外觀提供了可能。


設(shè)置圖形的標(biāo)題

如何設(shè)置一幅圖形的標(biāo)題?

示例數(shù)據(jù)需要加載 gcookbook 包,其中的 heightweight 數(shù)據(jù)集:

> library(gcookbook)
> str(heightweight)
'data.frame':   236 obs. of  5 variables:
 $ sex     : Factor w/ 2 levels "f","m": 1 1 1 1 1 1 1 1 1 1 ...
 $ ageYear : num  11.9 12.9 12.8 13.4 15.9 ...
 $ ageMonth: int  143 155 153 161 191 171 185 142 160 140 ...
 $ heightIn: num  56.3 62.3 63.3 59 62.5 62.5 59 56.5 62 53.8 ...
 $ weightLb: num  85 105 108 92 112 ...

使用 ggtitle 設(shè)置標(biāo)題或者 labs進(jìn)行設(shè)置。

p <- ggplot(data = heightweight, aes(x = ageYear, y = heightIn)) + geom_point()

p + ggtitle("Age and Height \nof Schoolchildren")

[圖片上傳失敗...(image-2559fe-1699922015360)]

使用labs

p <- ggplot(data = heightweight, aes(x = ageYear, y = heightIn)) + geom_point()

p + labs(title = "Age and Height of Schoolchildren")

[圖片上傳失敗...(image-a636b5-1699922015360)]


以上。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容