I'm plotting some hemispheric fields with ggplot2 and when I try to project them into a stereographic projection it takes ages to render. This is a minimal example:
lat <- seq(-87.159, -2, by = 3.7)
lon <- seq(0, 360, by = 3.75)
month <- 1:12
gdata <- expand.grid(lat = lat, lon = lon, month = month)
gdata$z <- rnorm(nrow(gdata))
g <- ggplot(gdata, aes(lon, lat)) +
geom_tile(aes(fill = z)) +
facet_wrap(~month, ncol = 4)
benchplot(g)
I get:
step user.self sys.self elapsed
1 construct 0.000 0.000 0.000
2 build 0.156 0.004 0.162
3 render 0.976 0.016 0.990
4 draw 0.464 0.000 0.464
5 TOTAL 1.596 0.020 1.616
If I add a projection with coord_map()
benchplot(g + coord_map("stereographic", orientation = c(-90,0, -120)))
it takes ~130 times longer.
step user.self sys.self elapsed
1 construct 0.008 0.000 0.004
2 build 39.520 0.184 40.612
3 render 147.744 0.060 147.968
4 draw 17.884 0.004 17.902
5 TOTAL 205.156 0.248 206.486
Is there a way to speed this up? I feel that a 100+ fold increase in render time is too much.