Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving ggplot2 Plot to be Rendered on Another System

Tags:

r

ggplot2

I haven't seen this question around anywhere in the last three years so I was looking for a more up-to-date answer. I have about ten plots that I've created in ggplot2 that I'm going to be rendering for web publication. I haven't been able to make sense of the articles and posts I've read concerning the lack of anti-aliasing on Windows builds of R. Ideally, I would be able to simply render them on my Windows laptop and export straight from there. The next best thing that I think might be simpler would be saving the plots as objects somehow and loading them on my Mac and rendering on there. I know I could run the scripts used for them on my Mac and go through the full process but I have quite a few dependencies (specifically file locations and such for my data) that I would have to edit before I could even run them. This is my current plan, but I'm sure there's a better way. If anyone has suggestions please send my way and thank you!

like image 628
Jason Pevitt Avatar asked Dec 21 '25 08:12

Jason Pevitt


1 Answers

Use save and load, both available from base R:

save(p,file='~/p.Rdata')

and on another computer:

load('~/p.Rdata')

where p is your plot, e.g.:

p <- ggplot(data.frame(x=1:5,y=runif(5))) + aes(x=x,y=y) + geom_point()
like image 103
Marat Talipov Avatar answered Dec 23 '25 20:12

Marat Talipov