I have a series of ggplot objects that I\'m trying to save to an .rdata file to load into a Markdown document later. The ggplot object itself is quite small (a few KB). But,
I stumbled upon this problem as well. This is indeed related to the environment. If you want to save your plots as an Rdata
file, then you should be creating a new environment inside the function that is generating your plot, so that the complete environment doesn't get saved. Example:
makePlot <- function(plot.data){
env <- new.env(parent = globalenv())
env$subset <- plot.data
my.plot <- with(env, {
my.plot <- ggplot(subset, ...)
return(my.plot)
})
return(my.plot)
}