1.从一个简单的boxplot开始
rm(list = ls()) #清空所有环境变量
if(!require(ggplot2))install.packages('ggplot2') #条件安装ggplot2
library(ggplot2) #加载ggplot2
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot() #利用内置数据集iris

001.png
2.利用theme_set()修改
theme_set(theme_classic())
ggplot(iris,aes(x = Species,y = Sepal.Length, fill = Species))+
geom_boxplot()

002.png
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')

003.png
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')

004.png
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))

005.png
备注
+ coord_polar() #转换为极坐标
+ coord_flip() #交换X轴和Y轴
dev.off() #关闭画板设备
网友评论