r - In knitting Rmd file, print 2 plots in same row, but create separate pdfs -
i have 2 plots in rmd file plot side-by-side in knitted output. save individual plots separate pdfs. when had 1 plot per device, dev.copy2pdf
worked avoid replotting, @ costs.
however, following code yields 2 pdfs, neither of desired output. first pdf first plot on left half of page; second pdf plots side-by-side. understand why happening - after all, copying directly current device, i'm not sure how modify code achieve result want.
data(cars) par(mfrow=c(1,2)) plot(cars$price,cars$mileage) dev.copy2pdf(file = "price-mileage.pdf") plot(cars$price,cars$doors) dev.copy2pdf(file = "price-doors.pdf")
i can't see way can asking in 1 step. can without replotting in knitr if mean.
```{r} data(iris) ``` create side side plots in knitr: ```{r fig.width=7, fig.height=6} par(mfrow=c(1,2)) plot(iris$sepal.length,iris$sepal.width) plot(iris$sepal.length,iris$petal.length) ``` ```{r include=f} #this write plots individual files. #it not appear in knitr because include=f pdf("plot1.pdf") plot(iris$sepal.length,iris$sepal.width) dev.off() pdf("plot2.pdf") plot(iris$sepal.length,iris$petal.length) dev.off() ```
Comments
Post a Comment