Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save an object through GGally in R

Tags:

r

ggplot2

ggally

I have a pretty dumb question to ask everyone.

I am using ggpairs under GGally to create a correlation matrix, and somehow I found that GGally did not provide a saving function as ggplot2 did. The function ggsave did not work for a non-ggplot2 object. I tried to use pdf or png, but they did not work. I am wondering if there's an easy to save this picture to a local file? Thank you for your kind help.

like image 864
Xinting WANG Avatar asked Oct 30 '14 12:10

Xinting WANG


1 Answers

While @CMichael's comment is nice (I didn't know that, hence +1), it's applicable only if you want to save a particular plot from GGally-generated plot matrix. I believe that you'd like to save the whole plot matrix - the need, which I've recently also experienced. Therefore, you can use a standard R approach and save the graphics by opening corresponding (to desired format) graphical device, printing the object and closing the device, which will effectively save the graphics in a desired format.

# use pdf() instead of svg(), if you want PDF output
svg("myPlotMatrix.svg", height = 7, width = 7)
g <- ggpairs(...)
print(g)
dev.off()
like image 170
Aleksandr Blekh Avatar answered Sep 22 '22 21:09

Aleksandr Blekh