ggplot2的主題設(shè)置

ggplot2畫(huà)圖的時(shí)候有幾個(gè)默認(rèn)主題,畫(huà)圖的時(shí)候我們可以自己挑選一個(gè)喜歡的內(nèi)置主題,也可以自己設(shè)置。其中內(nèi)置主題有以下幾個(gè),我們用iris數(shù)據(jù)集看一下效果:

  1. theme_bw
data(iris)

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + 
  geom_point() + geom_smooth(method = 'lm') + theme_bw()
image

2. theme_classic

image

3. theme_dark

image

4. theme_gray

image
  1. theme_light
image

6. theme_void

image
  1. theme_linedraw
image
  1. theme_minimal
image

如果要全局設(shè)置某一種主題的話,那么在開(kāi)頭寫(xiě)上theme_set()即可:

# 比如設(shè)置theme_bw
theme_set(theme_bw()) 

如果不用內(nèi)置的主題設(shè)置,或者我們想自己進(jìn)行一些微調(diào)也是可以的, 只要修改theme()函數(shù)即可,如下所示:

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + 

這樣可以讓圖片設(shè)置為方形,并且標(biāo)題居中顯示:

image

刪掉網(wǎng)格線并且背景顏色設(shè)置為白色:

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + 
image

歡迎關(guān)注!

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

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

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