不知道大家在为自己的文章绘图的时候总觉得不是那么完美。老是想自己手动改改,可是呢,AI呀PS呀又是一塌糊涂。今天我就为大家介绍一个可以讲R语言绘制的图形直接导入PPT/word并且可以进行修改的R包export。
其安装就是install.packages(“export”)。我们就不赘述了。接下来我们讲解下这个包的具体操作。主要分为三部分:一是输出位图图像格式(png,jpg,tif);二是输出offices格式(word,ppt);三是输出矢量图象格式(pdf,eps,svg)
首先看下位图图像绘制:

其中主要的参数是:dpi 分辨率。使用单独的函数绘制默认是300,当然可以自设。
Bg 图像的背景颜色。
Cairo 这个参数主要是在Linux下导出图像时候会用,其他时候没啥区别。
Tiffcompression 主要是图像的压缩格式设置,在一些科研文章中会要求。
具体的实例如下:
library(export)
library(ggplot2)
library(datasets)
filen <- tempfile(pattern = "ggplot")
x=qplot(Sepal.Length, Petal.Length, data = iris,
color = Species,size = Petal.Width, alpha = I(0.7))
x

graph2png(x=x, file=filen, dpi=400)

graph2tif(x=x, file=filen, dpi=400, height = 5)

graph2jpg(x=x, file=filen, dpi=400, height = 5, aspectr=4)

以上的运行结果对图像的大小是有区别的:

接下来我们看下offices格式的输出函数:

其中主要的参数:append主要负责输出到offices中是进行覆盖还是追加数据。
Paper主要是设置纸张的大小。
具体的实例:
graph2ppt(x=x, file=filen)

graph2doc(x=x, file=filen, aspectr=0.5)

graph2ppt(file=filen, width=9, aspectr=2, append = TRUE)

graph2doc(file=filen,aspectr=1.7, append =TRUE)

如果我们将图像选中然后取消组合,神奇的事情发生了,所有的点以及文字全部可以再编辑。

最后就是矢量图的输出:

其中也没啥主要的参数了,需要的参考前面的就行,这里的区别就是分辨率默认600.
具体实例:
graph2svg(x=x, file=filen, aspectr=2, font = "Times NewRoman",
height = 5, bg= "white")

graph2pdf(x=x, file=filen, aspectr=2, font ="Arial",
height = 5, bg= "transparent")

graph2eps(x=x, file=filen, aspectr=2, font ="Arial",
height = 5, bg= "transparent")
