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

# Create a file namefilen <- "table_aov" # or# filen <- paste("YOUR_DIR/table_aov")# Generate ANOVA outputfit=aov(yield ~ block + N * P + K, data = https://www.520longzhigu.com/shenghuo/npk) #'npk' dataset from base 'datasets'x=summary(fit)# Save ANOVA table as a CSV### Option 1: pass output as object# 输出对象table2csv(x=x,file=filen, digits = 1, digitspvals = 3, add.rownames=TRUE)# 屏幕输出导出到文件### Option 2: get output from consolesummary(fit)table2csv(file=filen, digits = 2, digitspvals = 4, add.rownames=TRUE)# Save ANOVA table as an Excel# Without formatting of the worksheetxtable2excel(file=filen, sheetName="aov_noformatting", digits = 1, digitspvals = 3, add.rownames=TRUE)# 更多参数# With formatting of the worksheettable2excel(x=x,file=filen, sheetName="aov_formated", append = TRUE, add.rownames=TRUE, fontName="Arial", fontSize = 14, fontColour = rgb(0.15,0.3,0.75), border=c("top", "bottom"), fgFill = rgb(0.9,0.9,0.9), halign = "center", valign = "center", textDecoration="italic")
原始数据的表格:
转换格式之后的,在console中的数据:


文件(csv和excel)中表格数据:
导出为Word中的表,再也不用复制粘贴调格式了 table2officetable2ppt: 导出统计输出到Microsoft Office PowerPoint/ LibreOffice Impress演示文稿中的表
table2doc: 将统计输出导出到Microsoft Office Word/ LibreOffice Writer文档中的表
table2office(x = NULL, file = "Rtable", type = c("PPT", "DOC"),append = FALSE, digits = 2, digitspvals = 2, trim.pval = TRUE,width = NULL, height = NULL, offx = 1, offy = 1,font = ifelse(Sys.info()["sysname"] == "Windows", "Arial","Helvetica")[[1]], pointsize = 12, add.rownames = FALSE)
# Create a file namefilen <- "table_aov"# filen <- paste("YOUR_DIR/table_aov")# Generate ANOVA outputfit=aov(yield ~ block + N * P + K, data = https://www.520longzhigu.com/shenghuo/npk) #'npk' dataset from base 'datasets'# Save ANOVA table as a PPT### Option 1: pass output as objectx=summary(fit)table2ppt(x=x,file=filen, digits = 1, digitspvals = 3, add.rownames =TRUE)### Option 2: get output from consolesummary(fit)table2ppt(x=x,file=filen, width=5, font="Times New Roman", pointsize=14, digits=4, digitspvals=1, append=TRUE, add.rownames =TRUE) # append table to previous slide# Save ANOVA table as a DOC filetable2doc(x=x,file=filen, digits = 1, digitspvals = 3, add.rownames =TRUE)summary(fit)table2doc(file=filen, width=3.5, font="Times New Roman", pointsize=14, digits=4, digitspvals=1, append=TRUE, add.rownames =TRUE) # append table at end of document
将表格数据导出到ppt和word中:
table2textable2html: 导出统计输出到HTML表 。
table2tex(x = NULL, file = "Rtable", type = "TEX", digits = 2,digitspvals = 2, trim.pval = TRUE, summary = FALSE, standAlone = TRUE,add.rownames = FALSE, ...)
summary:是否汇总数据文件 。
standAlone:导出的Latex代码应该是独立可编译的,还是应该粘贴到另一个文档中 。
add.rownames:是否应该将行名添加到表中(在第一列之前插入一列) 。
# Create a file namefilen <- tempfile(pattern = "table_aov") # or# filen <- paste("YOUR_DIR/table_aov")# Generate ANOVA outputfit=aov(yield ~ block + N * P + K, data = https://www.520longzhigu.com/shenghuo/npk) #'npk' dataset from base 'datasets'x=summary(fit)# Export to Latex in standAlone formattable2tex(x=x,file=filen,add.rownames = TRUE)# Export to Latex to paste in tex documentsummary(fit) # get output from the consoletable2tex(file=filen, standAlone = FALSE,add.rownames = TRUE)# Export to HTMLtable2html(x=x,file=filen) # orsummary(fit) # get output from the consoletable2html(file=filen,add.rownames = TRUE)
导出到html或tex中的表格数据:


R统计和作图