转载自:http://site.douban.com/182577/widget/notes/10568279/note/257294505/
ggplot2包的最新0.93版本允许自定义主题,这样ggplot的表现力可以通过各种不同的主题获得提升。
ggthemes包就是ggplot2的主题扩展包,提供了供ggplot2使用的新主题,尺度,几何对象和一些新函数。
其中最有趣的当然是那些新增主题(以及相应的调色板),它们给ggplot2提供了接近于媒体图片的效果。这样绘出的ggplot2图形看上去增色不少。
下面来尝试一下
先来张传统的ggplot版本
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point(alpha=.5)+ #透明度
scale_size_area()+ #区域和数值成比例
scale_colour_brewer(palette="Set1")+
ggtitle("Motor Trend Car Road Tests")
同样的画法,看看ggthemes包的主题:
excel-style:
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point()+
scale_size_area()+
theme_excel() +
scale_fill_excel()+
ggtitle("Motor Trend Car Road Tests")
economist-style:
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point(alpha=.5)+
scale_size_area()+
theme_economist() +
scale_colour_economist()+
ggtitle("Motor Trend Car Road Tests")
solarized-style:
深色版
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point()+
scale_size_area()+
theme_solarized(light=FALSE) +
scale_colour_solarized("red")+
ggtitle("Motor Trend Car Road Tests")
ggthemes包的
文档地址 http://cran.r-project.org/web/packages/ggthemes/ggthemes.pdf
代码地址 https://github.com/jrnold/ggthemes
除了这个包,网上还有人做了xkcd风格 http://store.xkcd.com/
http://stackoverflow.com/questions/13558619/theme-elements-in-ggplot2-figure
也很有意思。
ggthemes包就是ggplot2的主题扩展包,提供了供ggplot2使用的新主题,尺度,几何对象和一些新函数。
其中最有趣的当然是那些新增主题(以及相应的调色板),它们给ggplot2提供了接近于媒体图片的效果。这样绘出的ggplot2图形看上去增色不少。
下面来尝试一下
先来张传统的ggplot版本
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point(alpha=.5)+ #透明度
scale_size_area()+ #区域和数值成比例
scale_colour_brewer(palette="Set1")+
ggtitle("Motor Trend Car Road Tests")
![]() |

同样的画法,看看ggthemes包的主题:
excel-style:
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point()+
scale_size_area()+
theme_excel() +
scale_fill_excel()+
ggtitle("Motor Trend Car Road Tests")
![]() |

economist-style:
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point(alpha=.5)+
scale_size_area()+
theme_economist() +
scale_colour_economist()+
ggtitle("Motor Trend Car Road Tests")
![]() |

solarized-style:
深色版
ggplot(mtcars,aes(x=mpg,y=wt,size=cyl,colour=factor(gear)))+
geom_point()+
scale_size_area()+
theme_solarized(light=FALSE) +
scale_colour_solarized("red")+
ggtitle("Motor Trend Car Road Tests")
![]() |

ggthemes包的
文档地址 http://cran.r-project.org/web/packages/ggthemes/ggthemes.pdf
代码地址 https://github.com/jrnold/ggthemes
除了这个包,网上还有人做了xkcd风格 http://store.xkcd.com/
http://stackoverflow.com/questions/13558619/theme-elements-in-ggplot2-figure
也很有意思。