1.從一個(gè)簡(jiǎn)單的boxplot開始
rm(list = ls()) #清空所有環(huán)境變量
if(!require(ggplot2))install.packages('ggplot2') #條件安裝ggplot2
library(ggplot2) #加載ggplot2
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot() #利用內(nèi)置數(shù)據(jù)集iris
2.利用theme_set()修改
theme_set(theme_classic())
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot()
3.利用labs()修改
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot()+
labs(title = 'title from labs',subtitle = 'subtitle from labs',x ='',y='',caption = 'caption from labs')
4.利用theme()修改
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot()+
labs(title = 'title from labs',subtitle = 'subtitle from labs',x =NULL,y=NULL,caption = 'caption from labs')+
theme(legend.position = 'None')
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot()+
labs(title = 'title from labs',subtitle = 'subtitle from labs',x ='',y='',caption = 'caption from labs')+
theme(axis.text.x = element_text(angle=65, vjust=0.6))
備注
+ coord_polar() #轉(zhuǎn)換為極坐標(biāo)
+ coord_flip() #交換X軸和Y軸
dev.off() #關(guān)閉畫板設(shè)備