R语言Cairo包的使用

Cairo使用起来非常简单,和基础包grDevices中的函数对应。

  • CairoPNG---grDevices:png()。
  • CairoTIFF---grDevices:tiff()。
  • CairoPDF---grDevices:pdf()。
  • ...

查看Cairo所支持的图片格式:

#加载Cairo包
library(Cairo)
#检查所支持的图片格式
Cairo.capabilities()

 以iris数据集为例

> head(iris)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
>p = ggplot(iris,aes(x = Species,y = Sepal.Length,colour = Species))
> p+geom_point()
> plot1 = p+geom_point()
> library(Cairo)
#ggsave默认以Cairo处理图片
> ggsave("test1.png",plot1,width = 4,height = 3 )

posted @ 2015-08-26 16:55  yangk  阅读(7839)  评论(0编辑  收藏  举报