图片或表格输出为ppt格式 - export
2019-11-10 本文已影响0人
吴十三和小可爱的札记
1.简介
懒得调整ggplot2::theme时,可以将图片输出、然后手动调整。然鹅,不会AI,不会PS,只会用ppt。要是能把ggplot2图片输出成ppt格式就好了!!!
-
export,能将 active R graphs or ggplot2, lattice or base R plots输出为Microsoft office或其他矢量图和位图格式。
-
能将统计分析结果保存为table形式,并输出为 Excel, Word, PowerPoint, Latex or HTML格式。
2. 下载安装
从CRAN下载安装官方最新版
install.packages("export")
从github下载最新版
# install.packages("devtools")
devtools::install_github("tomwenseleers/export")</pre>
2. 参数
作者在github的文档里展示了几乎所有主要函数,参数可以慢慢去探索。
## export of ggplot2 plot
library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species,
size = Petal.Width, alpha = I(0.7))
# export to Powerpoint
graph2ppt()
graph2ppt(file="ggplot2_plot.pptx", aspectr=1.7)
# add 2nd slide with same graph 9 inches wide and A4 aspect ratio
graph2ppt(file="ggplot2_plot.pptx", width=9, aspectr=sqrt(2), append=TRUE)
# add 3d slide with same graph with fixed width & height
graph2ppt(file="ggplot2_plot.pptx", width=6, height=5, append=TRUE)
# export to Word
graph2doc()
# export to bitmap or vector formats
graph2svg()
graph2png()
graph2tif()
graph2jpg()
## export of aov Anova output
fit=aov(yield ~ block + N * P + K, npk)
x=summary(fit)
# export to Powerpoint
table2ppt(x=x)
table2ppt(x=x,file="table_aov.pptx")
table2ppt(x=x,file="table_aov.pptx",digits=4,append=TRUE)
table2ppt(x=x,file="table_aov.pptx",digits=4,digitspvals=1,
font="Times New Roman",pointsize=16,append=TRUE)
# export to Word
table2doc(x=x)
# export to Excel
table2excel(x=x, file = "table_aov.xlsx",digits=4,digitspvals=1,
sheetName = "Anova_table", add.rownames = TRUE)
# export to Latex
table2tex(x=x)
# export to HTML
table2html(x=x)