mike
mike

Reputation: 951

RStudio Exporting Issues

I have never really needed to export anything from RStudio with specific dimensions. Now I am producing some graphs for a publication with a strict width of 2400 pixels. My major problem is that I have not used a singular traditional plot for what I have done. I have really customised my graph with various plots and segments. To evaluate the plot as I have been making it, I have been looking at the zoomed in plot in RStudio.

So What I am asking is whether there was a way I could export exactly that zoomed in plot on RStudio to a png with the specified width (height, I am fairly flexible with).

I have tried

dev.copy2pdf(device = "pdf", file = "test.pdf")

Which didn't work as I had hoped.

Upvotes: 1

Views: 2167

Answers (1)

Steve Rowe
Steve Rowe

Reputation: 19413

If you are using ggplot, you can use ggsave:

qplot(rating, data=movies, geom="histogram")
ggsave("test.pdf", height=8, width=8)

The default DPI is 300 so 300 DPI x 8 inches = 2400.

This should do the same in the base plotting system:

pdf("boxplot.pdf", height=8, width=8)
boxplot(mtcars$mpg)
dev.off()

Upvotes: 1

Related Questions