R可視化——基于ggplot2包繪圖的模板主題樣式匯總

繪制基本散點(diǎn)圖

rm(list = ls())
#加載R包
library(ggplot2)

#數(shù)據(jù)——以R自帶示例數(shù)據(jù)iris為例
df<-iris

#繪制基本散點(diǎn)圖
p<-ggplot(df) + 
  geom_point(aes(x = Sepal.Length, y = Sepal.Width, 
                           alpha=  Petal.Length , 
                           color = Species, 
                           size = Petal.Width))
p
image.png

ggplot2默認(rèn)主題

1、theme_gray()
p1<-p+theme_gray()+ggtitle("theme_gray()")+
  theme(legend.position = 'none')
p1
image.png
2、theme_bw()
p2<-p+theme_bw()+ggtitle("theme_bw()")+
  theme(legend.position = 'none')
p2
image.png
3、theme_classic()
p3<-p+theme_classic()+ggtitle("theme_classic()")+
  theme(legend.position = 'none')
p3
image.png
4、theme_light()
p4<-p+theme_light()+ggtitle("theme_light()")+
  theme(legend.position = 'none')
p4
image.png
5、theme_void()
p5<-p+theme_void()+ggtitle("theme_void()")+
  theme(legend.position = 'none')
p5
image.png
6、theme_linedraw()
p6<-p+theme_linedraw()+ggtitle("theme_linedraw()")+
  theme(legend.position = 'none')
p6
image.png
7、theme_minimal()
p7<-p+theme_minimal()+ggtitle("theme_minimal()")+
  theme(legend.position = 'none')
p7
image.png
8、theme_dark()
p8<-p+theme_dark()+ggtitle("theme_dark()")+
  theme(legend.position = 'none')
p8
image.png
cowplot::plot_grid(p1,p2,p3,p4,p5,p6,p7,p8,ncol = 4)
image.png

ggthemes拓展主題

#加載包
library(ggthemes)
1、theme_clean()
p+theme_clean()
image.png
2、theme_calc()
p+theme_calc()
image.png
其他主題如下,具體展示圖片見(jiàn)公眾號(hào)推文
p+theme_economist()
p+theme_igray()
p+theme_fivethirtyeight()
p+theme_pander()
p+theme_foundation()
p+theme_base()
p+theme_par()
p+theme_gdocs()
p+theme_map()
p+theme_few()
p+theme_tufte()
p+theme_stata()
p+theme_excel()
p+theme_wsj()
p+theme_hc()
p+theme_solid()
p+theme_solarized()

ggprism包拓展主題

#加載包
library(ggprism)
names(ggprism_data$themes)
#44種主題樣式名稱(chēng),通過(guò)替換名稱(chēng)可實(shí)現(xiàn)更換主題風(fēng)格目的
image.png

示例,具體細(xì)節(jié)可參考此前推文:

p+theme_prism(palette = "autumn_leaves")
image.png
p+theme_prism(palette = "pearl")
image.png
p+theme_prism(palette = "summer")
image.png
p+theme_prism(palette = "spring")
image.png
p+theme_prism(palette = "ocean")
image.png

BBC風(fēng)格---bbplot

#安裝包
devtools::install_github('bbc/bbplot')
#加載包
library(bbplot)
#使用方式
p+bbc_style()

具體細(xì)節(jié)可參見(jiàn)文章:http://m.itdecent.cn/p/c1436793ad67

image.png

更多主題樣式詳見(jiàn)公眾號(hào)【科研后花園】推文!

?著作權(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)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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