What happens to plot_env when I save a ggplot2 object?

Hey guys. I have known that ggplot2 object will contain a plot_env slot with everything in the current env.
But when I save a ggplot2 object drawn by myself, which means I used ggplot()+geom_something() to drawn it rather than Seurat::Dimplot(), and read the rds in a new R session, the plot_env only contains .Random.seed, p and a function set_proxy which is loaded by my .Rprofile.
image

So what determines the content of plot_env in a saved rds file?

By the way, the ggplot2 object p itself, can be call in plot_env, so it can form something like p$plot_env$p$plot_env$p$plot_env$p, will it cause redundancy save in rds or Rdata file?

I hope to save my plot in both pdf and rds way, so it can be easily modified oneday. But plot produced by Seurat usually contain a seurat object in the plot_env so the file is extremly huge and slow. I know it can be fix by extract out the meta.data before generate ggplot2 object like:

data<-seurat_object@meta.data
p<-ggplot(data)+geom_violin()

But I still think it is a bit wierd that plot_env will contain the fully seurat_object besides the meta.data only.

I don't think plot_env think is used for much except scales. Have a look at Drop plot_env from ggplot2 objects? · Issue #3994 · tidyverse/ggplot2 · GitHub

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.