ggplot2 提供了许多不同的主题,默认主题是 theme_gray(),它使用灰色背景和白色网格线,那么这些主题是什么样子呢?由于我经常忘记这些主题长什么样子,于是都画出来方便下次需要的时候看一看。
1. theme_gray()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()
2. theme_bw()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_bw()
3. theme_classic()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_classic()
4. theme_dark()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_dark()
5. theme_light()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_light()
6. theme_linedraw()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_linedraw()
7. theme_minimal()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_linedraw()
8. theme_void()
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_void()
9. my plot
ggplot(mtcars, aes(x=mpg, y=cyl))+
geom_point()+
theme_bw()+
theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())
如何设置全局主题呢?
theme_set(theme_classic())