首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用addImage在ReporteRs中并排打印

使用addImage在ReporteRs中并排打印
EN

Stack Overflow用户
提问于 2016-08-03 19:11:34
回答 1查看 524关注 0票数 1

我正在使用ReporteRs包自动创建一个docx文档。为此,我需要将两个外部图像并排放置。这不是一个在R中使用它们之前手动组合它们的选项,因为这将是大量的组合。

代码语言:javascript
复制
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")

我如何做到这一点,以使地块并排,而不是在另一个下面/上面?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-04 22:00:43

这里有两种不同的方法:

代码语言:javascript
复制
# png(filename = "image1.png")
# barplot(1:10)
# dev.off()
# 
# png(filename = "image2.png")
# barplot(1:10)
# dev.off()

library(ReporteRs)
library(magrittr)

方法1:使用节

代码语言:javascript
复制
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")

方法2:使用表格

代码语言:javascript
复制
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")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38741930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档