How can I produce more than one file format per plot code in R?
image, plot, r
Solution
Or you can use `dev.copy`:
plot(cars)
dev.copy(jpeg, "cars.jpeg")
dev.off()
dev.copy(pdf, "cars.pdf")
dev.off()
Problem
I use Github markdown to document my data analysis with R. When I make a plot I use: ``` jpeg("file_name.jpg") plot(...) dev.off() ``` to save the plot as a jpeg that can then be embedded and displayed in the markdown document like this: ``` !(file_name.jpg) ``` However, I also need to make a `pdf` of the plot for the final publication. Currently I write the entire plot code over again with `pdf("file_name.pdf")` but this results in a lot of basically duplicate code. I have tried putting the `jpeg` and `pdf` calls in sequence but then only the bottom one gets produced. Is there a way to make the `jpeg` and `pdf` file from the same code during only one run of the code?