万能转换:R图和统计表转成发表级的Word、PPT、Excel、HTML( 三 )


导出到office(ppt和word)中的图形,是可编辑的:
其它导出到ppt的例子(设置长宽比)
graph2ppt(file="ggplot2_plot.pptx", aspectr=1.7)
增加第二张同样的图,9英寸宽和A4长宽比的幻灯片 (append=T,追加)
graph2ppt(file="ggplot2_plot.pptx", width=9, aspectr=sqrt(2), append=TRUE)
添加相同图形的第三张幻灯片,宽度和高度固定
graph2ppt(file="ggplot2_plot.pptx", width=6, height=5, append=TRUE)
禁用矢量化图像导出
graph2ppt(x=x, file=filen, vector.graphic=FALSE, width=9, aspectr=sqrt(2), append = TRUE)
用图填满幻灯片
graph2ppt(x=x, file=filen, margins=0, upscale=TRUE, append=TRUE)
输出矢量图

  • graph2svg: 将当前的R图保存为SVG格式
  • graph2pdf: 将当前的R图保存为PDF格式
  • graph2eps: 将当前的R图保存为EPS格式
函数参数解释
graph2vector(x = NULL, file = "Rplot", fun = NULL, type = "SVG",aspectr = NULL,width = NULL, height = NULL, scaling = 100,font = ifelse(Sys.info()["sysname"] == "Windows","Arial","Helvetica")[[1]], bg = "white", colormodel = "rgb",cairo = TRUE,fallback_resolution = 600, ...)
  • fallback_resolution: dpi中的分辨率用于栅格化不支持的矢量图形 。
#需运行上面的ggplot2绘图# Create a file namefilen <- "output_filename" # or# filen <- paste("YOUR_DIR/ggplot")# There are 3 ways to use graph2vector():### 1. Pass the plot as an object# 导出图形对象graph2svg(x=x, file=filen, aspectr=2, font = "Times New Roman",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")# 导出当前预览窗口呈现的图### 2. Get the plot from current screen devicexgraph2svg(file=filen, aspectr=2, font = "Arial",height = 5, bg = "transparent")graph2pdf(file=filen, aspectr=2, font = "Times New Roman",height = 5, bg = "white")graph2eps(file=filen, aspectr=2, font = "Times New Roman",height = 5, bg = "white")# 导出自定义函数输出的一系列图### 3. Pass the plot as a functiongraph2svg(file=filen, fun = plot.fun, aspectr=2, font = "Arial",height = 5, bg = "transparent")graph2pdf(file=filen, fun=plot.fun, aspectr=2, font = "Arial",height = 5, bg = "transparent")graph2eps(file=filen, fun=plot.fun, aspectr=2, font = "Arial",height = 5, bg = "transparent")
转换3D图形rgl2png: 将当前的rgl 3D图形保存为PNG格式 。
rgl2bitmap(file = "Rplot", type = c("PNG"))
# Create a file namefilen <- tempfile("rgl") # or# filen <- paste("YOUR_DIR/rgl")# Generate a 3D plot using 'rgl'x = y = seq(-10, 10, length = 20)z = outer(x, y, function(x, y) x^2 + y^2)rgl::persp3d(x, y, z, col = 'lightblue')# Save the plot as a pngrgl2png(file = filen)# Note that omitting 'file' will save in current directory
生成的3D图形:
将生成的3D图形保存为PNG格式:
输出统计结果到表格 table2spreadsheet
  • table2excel: 导出统计输出到Microsoft Office Excel/ LibreOffice Calc电子表格中的一个表.
  • table2csv:将统计输出以CSV格式导出到表中(“,”表示值分隔,“ 。”表示小数)
  • table2csv2: 将统计输出以CSV格式导出到表中(“;”表示值分隔,”,”表示小数)
table2spreadsheet(x = NULL, file = "Rtable", type = c("XLS", "CSV","CSV2"), append = FALSE, sheetName = "new sheet", digits = 2,digitspvals = 2, trim.pval = TRUE, add.rownames = FALSE, ...)