ggthemes包:丰富ggplot2的表现力
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
也很有意思。
str(veh.tab.all)
'data.frame': 6711 obs. of 4 variables:
$ vehicle : int 1 27 1 1 2 4 21 23 1 21 ...
$ entrystation: int 1404108 1404108 1404110 1404111 1404111 1404111 1404111 1404111 1404201 1404201 ...
$ exitstation : int 1401101 1401101 1401101 1401101 1401101 1401101 1401101 1401101 1401101 1401101 ...
$ traveltime : int 3 1 8 53 1 1 2 1 16 2 ...
p=ggplot(data=veh.tab.all,aes(x=vehicle,y=traveltime))
p+geom_bar(stat="identity")+
facet_grid(entrystation~exitstation,margin=T,scales="free")
画了有十几分钟了,图还是没有生成出来,请问是ggplot的问题呢还是其他原因
$ entrystation的取值太多了吧,是不是没报错就是画的特别慢?
entrystation和exitstation一共有30个组合。代码没有问题,2000行左右的数据很快就出来,扩展到6千加之后就一直出不来。
代码肯定是没问题。我觉得就是数据量大。要不换lattice试试。
或者参考一下这个http://yanping.me/cn/blog/2012/01/01/working-with-large-datasets/
可能真的是数据量太大了,我用lattice也试过了,还是出不来图。
> 我来回应