ggplot2畫(huà)圖的時(shí)候有幾個(gè)默認(rèn)主題,畫(huà)圖的時(shí)候我們可以自己挑選一個(gè)喜歡的內(nèi)置主題,也可以自己設(shè)置。其中內(nèi)置主題有以下幾個(gè),我們用iris數(shù)據(jù)集看一下效果:
- 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
- theme_light
image
6. theme_void
image
- theme_linedraw
image
- 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)注!