1

I am making plot in R of some SpatialPolygonDataFrames, but it takes forever. I needed three hours to save to a png the plot of one of these layers that has 314 elements and weights (as said by RStudio) 35 Mb. I do not know if that is a lot or not, but it does not take more than a fraction of a second to display it in a GIS software such as QGIS or ArcMap.
It makes so small sense that I wonder if this is how it is supposed to be or something is wrong in my setup. This is the code I am using, where APpat is a shapefile of protected areas

> library(rgdal)
> library(rasterVis)
> APpat <- readOGR("./PAT", "AP_PAT_edited1")
> PAT.alt <- raster("./altitude") # I plot the polygons over this raster, which is very light to plot on its own

# This is how APpat looks like
> APpat

class       : SpatialPolygonsDataFrame 
features    : 314 
extent      : -92.58878, -57.4542, -22.9007, 13.39352  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
variables   : 6
names       :   id,                    category,             name, year,   country,       IUCN 
min values  :    1, Area Nacional de Recreacion, Abra de Rio Frio, 1936,   Bolivia,          I 
max values  : SN09,                  Via Parque,           Yurubi, 2015, Venezuela, VI

# And then save the plot to png
> png(paste0("./ProtectedAreas.png"), width=1300, heigh=1300, res=300)
> levelplot(PAT.alt, margin=FALSE, 
        at=seq(0,6800, by=2000), 
        main=paste0("Protected areas, ", years[y]),
        par.settings=mytheme,
        xlab=NULL, ylab=NULL,
        contour = TRUE, col='dark green',
        colorkey=NULL) +
> layer(sp.polygons(myAP, lwd=0.8, col='black', fill="#fc9272"))
> par(cex=.7)
> dev.off()

It took 3 hours 7 minutes to plot. I have tried using normal plot instead of levelplot as well, with equivalent results. The same if I am not plotting the raster, but the polygons on their own.

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.4

I have installed XQuartz. I find similar times when just plotting inside RStudio and when saving the plot to a pdf file. Thanks for your help!

EDIT: This is the shapefile layer I am trying to plot: https://drive.google.com/open?id=0B0XRH7FN95-RSzFRckhXNjVWYlk

EDIT2: It is not a generalizable problem, seems to happen only to me. We were able to plot the figure in different machines in ~20 secs. Still, if someone has an idea what can be wrong with my computer, it will be much appreciated!

Javier Fajardo
  • 737
  • 1
  • 10
  • 22
  • Hi. Could you share the Shapefile so that we can check? – lbusett Apr 20 '17 at 06:31
  • Thanks @LoBu, I uploaded the shapefile! – Javier Fajardo Apr 20 '17 at 16:18
  • On my PC, plotting that shape using `plot` or `spplot` doesn't take more than 20 seconds, so it seems that it's something related to your machine. Dod you already try updating all R packages ? – lbusett Apr 21 '17 at 12:57
  • Oh... thanks @LoBu, that was useful. I got the opportunity to try on a different computer and it was as you said: not instant, but no longer than 20 seconds. Now I know it is something with my machine... However, I have updated all my packages... and I still have the same problem. I work all the time plotting this kind of objects and it is really difficult to work like this. It doesn't take always hours... but minutes is very common. Does anyone has an idea what can be wrong with my machine? Thanks! – Javier Fajardo Apr 21 '17 at 18:08
  • What is PAT.alt? Can you print that as well? Presume it's an ADF or GDB given the path, so maybe use readAll on it but I'm guessing – mdsumner Apr 25 '17 at 21:08

0 Answers0