dkahle / ggmap

A package for plotting maps in R with ggplot2
763 stars 231 forks source link

Allow environment = emptyenv() to reduce the size of serialized ggmaps #173

Open jefshe opened 6 years ago

jefshe commented 6 years ago

I've noticed serializing simple plots e.g.

> object.size(serialize(ggmap(get_map('Europe', zoom=4)),NULL))
148010056 bytes

Leads to very large R objects > 140MB

This can make it quite annoying when transferring these objects over a network. What causes such crazy sizes?

mvkorpel commented 6 years ago

ggmap() returns a ggplot object. By default, ggplot() keeps a reference to the environment where it was called. When serialized, the environment may be very large. @dkahle It might be possible to use ggplot(..., environment = emptyenv()) to mitigate this.