R 使用addImage在记者中并排绘图
我正在使用ReporteRs包自动创建docx文档。为此,我需要将两个外部图像并排放置。在R中使用它们之前,是否可以手动组合它们 ,因为这将是大量的组合R 使用addImage在记者中并排绘图,r,reporters,R,Reporters,我正在使用ReporteRs包自动创建docx文档。为此,我需要将两个外部图像并排放置。在R中使用它们之前,是否可以手动组合它们 ,因为这将是大量的组合 library("ReporteRs") doc <- docx() doc <- addImage(doc,"image1.png",par.properties = parLeft(), height=1, width=1) doc <- addImage(doc,"image2.png",par.properties =
library("ReporteRs")
doc <- docx()
doc <- addImage(doc,"image1.png",par.properties = parLeft(), height=1, width=1)
doc <- addImage(doc,"image2.png",par.properties = parLeft(), height=1, width=1)
writeDoc(doc, file = "example.docx")
图书馆(“记者”)
doc这里有两种不同的方法:
# png(filename = "image1.png")
# barplot(1:10)
# dev.off()
#
# png(filename = "image2.png")
# barplot(1:10)
# dev.off()
library(ReporteRs)
library(magrittr)
方法1:使用一个截面
方法2:使用表格
dat我认为这可以用FlexTable来完成。我没有想到添加部分是一个选项。谢谢我用一些ggplots而不是图像尝试了这个方法,section方法添加了一个完整的分页符,table方法在我将我的图放入矩阵时返回一个错误。有什么解决方法吗?@DanChaltielpot_img
需要一个图像路径,而不是ggplot对象。
docx() %>%
addSection(ncol = 2, space_between = 0.1) %>%
addImage( "image1.png",par.properties = parLeft(), height=1, width=1) %>%
addColumnBreak() %>%
addImage( "image2.png",par.properties = parLeft(), height=1, width=1) %>%
addSection( ncol = 1 ) %>%
writeDoc( file = "example1.docx")
dat <- matrix("", nrow = 1, ncol = 2) # dummy empty table
# Flextable - one line, 2 columns
ft <- FlexTable(dat, header.columns = F, add.rownames = F)
ft[1,1] <- pot_img("image1.png", height=1, width=1) # add image1 to cell 1
ft[1,2] <- pot_img("image2.png", height=1, width=1) # add image2 to cell 2
docx() %>%
addFlexTable( ft ) %>%
writeDoc(file = "example2.docx")