Export a graph to R, as well as display it in knitr

I am using knitr and want my rmd file to create an eps file in shapes / folders whenever it starts. I found this question: Export the graph to an .eps file using R which does what I want but does not display the diagrams on the web page created by knitr, presumably because the postscript command simply redirects anything to the file, which you give him. I would like to display a graph and save it in a file. My code currently looks something like this:

```{r}
setEPS()
postscript("~/File/Path/To/Figures/Folder/Figure.eps")
par(mar=c(4, 4, 4, 10))
barplot(prop.table(t(testtable[2:4]), 2), names=testtable$Group, legend=c(colnames(testtable)[2:4]), args.legend=list(x=7, y=1), xlab="Groups", ylab="Percentage of Answers")
dev.off()
``` 

In knitr it gives

## pdf 
##   2

I would need to run the same header line command after dev.off () in order to produce something in knitr.

: 1) , knitr. 2) r , dev.off().

, .


, 3) Get knitr, eps. , unnamed_chunk_x.png, , . , , {r} -> {r ---}

+1
1

,

opts_chunk$set(dev=c('png','postscript'))

( png, eps). @Tyler, chunk-by-chunk, .

+2

Source: https://habr.com/ru/post/1656497/


All Articles