.Rmd ファイルがあり、関数 pandoc を使用して .docx ファイルを作成しようとしています。
最終的な解像度が 504x504 ピクセル (つまり、72dpi の 7x7 インチ) の図が必要です。残念ながら、デフォルトの 72 dpi は品質が低すぎるため、最終的な解像度を変更せずに 150 dpi に増やしたいと考えています (したがって、.docx ファイル内で既に正しいサイズになっています)。オプションの fig.width と fig.height=7 を保持し、dpi=150 に設定すると、必要な品質が得られますが、最終的な解像度が上がり、図が .docx マージンからはみ出します。引数 out.width と out.height で遊んでみましたが、それらを含めると、最終的な .docx には何もプロットされません。
アイデア?
.Rmd コードの例:
My title
-------------------------
*(this report was produced on: `r as.character(Sys.Date())`)*
That's my plot
```{r echo=FALSE}
plot(0,0,type="n",xlim=c(0,500), ylim=c(-12,0), las=1)
color <- rainbow(500)
text(380,-1,"Test",pos=4)
lseq <- seq(-6,-2,length.out=500)
for(j in seq_along(lseq)) {
lines(c(400,450), rep(lseq[j], 2), col=color[j])
}
polygon(c(400,450,450,400), c(-6,-6,-2,-2), lwd=1.2)
```
.docx への変換
library(knitr)
library(markdown)
knit("example.Rmd") # produces the md file
pandoc("example.md", format = "docx") #prodces the .docx file
フィギュアを再スケーリングしようとしても、うまくいきません。下:
My title
-------------------------
*(this report was produced on: `r as.character(Sys.Date())`)*
That's my plot
```{r echo=FALSE, dpi=150, fig.width=7, fig.height=7, out.width=504, out.height=504}
plot(0,0,type="n",xlim=c(0,500), ylim=c(-12,0), las=1)
color <- rainbow(500)
text(380,-1,"Test",pos=4)
lseq <- seq(-6,-2,length.out=500)
for(j in seq_along(lseq)) {
lines(c(400,450), rep(lseq[j], 2), col=color[j])
}
polygon(c(400,450,450,400), c(-6,-6,-2,-2), lwd=1.2)
```