SecretIndividual
SecretIndividual

Reputation: 2519

Receiving an error trying to use ggsave after ggpairs

I created a correlation plot:

library(nycflights13)
ggpairs(flights) +
  ggsave(filename = paste("overall_corr_plot.png"), path = paste(getwd(), "/images", sep = ""))

This gives me an error:

Error in `+.gg`(ggpairs(flights), ggsave(filename = paste("overall_corr_plot.png"),  :                                                        
  'ggmatrix' does not know how to add objects that do not have class 'theme' or 'labels'. Received object with class: 'NULL'
In addition: There were 15 warnings (use warnings() to see them)

It seems it's missing some data. Is it possible to fix this and if yes, how?

Upvotes: 2

Views: 203

Answers (1)

caldwellst
caldwellst

Reputation: 5956

You aren't adding ggsave to your plot, which is what the + denotes here. Just call ggsave after running your plot, it automatically saves the last plot sent to your graphics device.

ggpairs(flights)
ggsave(filename = paste("overall_corr_plot.png"), path = paste(getwd(), "/images", sep = ""))

Note that ggpairs on the entire flights data is going to be madness and you will have to drastically increase the cardinality_threshold, but that's not the issue here.

Upvotes: 3

Related Questions