Skip to content

Dramatically slow map plotting

5 messages · David Winsemius, Peter Dalgaard, Rolando Valdez

#
Hello, 

Recently, I acquired a MacBook Pro, Core i7, 8 GB ram. I Installed the newest R version, 3.0.3 from the web page. The problem is when I?m plotting maps, because is going very, very slow, about 3 or 4 minutes just for a single map, while I?ve done this in a few seconds in Windows with Core i5 and 4 GB ram.

This is what I have:

R version 3.0.3 (2014-03-06) -- "Warm Puppy"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)

[R.app GUI 1.63 (6660) x86_64-apple-darwin10.8.0]

I found a reproducible example in web and I took time with proc.time()

ptm <- proc.time()
library(sp)
library(lattice) # required for trellis.par.set():
trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()

# prepare nc sids data set:
library(maptools)
nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
arrow = list("SpatialPolygonsRescale", layout.north.arrow(),
offset = c(-76,34), scale = 0.5, which = 2)
#scale = list("SpatialPolygonsRescale", layout.scale.bar(),
#    offset = c(-77.5,34), scale = 1, fill=c("transparent","black"), which = 2)
#text1 = list("sp.text", c(-77.5,34.15), "0", which = 2)
#text2 = list("sp.text", c(-76.5,34.15), "1 degree", which = 2)
## multi-panel plot with filled polygons: North Carolina SIDS
spplot(nc, c("SID74", "SID79"), names.attr = c("1974","1979"),
colorkey=list(space="bottom"), scales = list(draw = TRUE),
main = "SIDS (sudden infant death syndrome) in North Carolina",
sp.layout = list(arrow), as.table = TRUE)

#    sp.layout = list(arrow, scale, text1, text2), as.table = TRUE)
proc.time() - ptm

user  system elapsed 
2.408   0.064   2.616

It was quick.

Then I did a single plot with my shape:

mapa <- readShapePoly(?Entidades_2013.shp?)
ptm <- proc.time()
spplot(mapa[1]); proc.time() - ptm

user  system elapsed 
87.575   0.786  88.068

Why it take a lot of time? I worked with same shapes in Windows and never took that time.

Hope you can help me,

Regards,
Rolando Valdez
#
On Mar 20, 2014, at 4:56 PM, Rolando Valdez wrote:

            
Most people use system.time and not proc.time.

When you execute proc.time you get something like:
user    system   elapsed 
   75.736    33.765 97374.066 

Is that meaningful to you? (It's not to me.)

When I wrap system.time around that set of expressions (inside RStudio on a 6 year-old MacPro) I get:

   user  system elapsed 
  0.065   0.001   0.066
#
On 21 Mar 2014, at 08:15 , David Winsemius <dwinsemius at comcast.net> wrote:

            
That'll be because you didn't print() the lattice plots, David. That saves a bundle on graphics I/O...

I get:
+ ptm <- proc.time()
+ library(sp)
+ library(lattice) # required for trellis.par.set():
+ trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()
+ 
+ # prepare nc sids data set:
+ library(maptools)
+ 
+ nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
+ arrow = list("SpatialPolygonsRescale", layout.north.arrow(),
+              offset = c(-76,34), scale = 0.5, which = 2)
+ #scale = list("SpatialPolygonsRescale", layout.scale.bar(),
+ #    offset = c(-77.5,34), scale = 1, fill=c("transparent","black"), which = 2)
+ #text1 = list("sp.text", c(-77.5,34.15), "0", which = 2)
+ #text2 = list("sp.text", c(-76.5,34.15), "1 degree", which = 2)
+ ## multi-panel plot with filled polygons: North Carolina SIDS
+ print(spplot(nc, c("SID74", "SID79"), names.attr = c("1974","1979"),
+        colorkey=list(space="bottom"), scales = list(draw = TRUE),
+        main = "SIDS (sudden infant death syndrome) in North Carolina",
+        sp.layout = list(arrow), as.table = TRUE))
+ 
+ #    sp.layout = list(arrow, scale, text1, text2), as.table = TRUE)
+ print(proc.time() - ptm)
+ })
   user  system elapsed 
  3.906   0.118   4.166 
   user  system elapsed 
  3.906   0.118   4.167
However, the thing that is slow for Ronaldo is not reproducible for us since we don't have
?Entidades_2013.shp?.

Peter D.

  
    
1 day later
#
El 21/03/2014, a las 01:15, David Winsemius <dwinsemius at comcast.net> escribi?:
Most people use Microsoft Windows, so? Is that a reasonable argument to use it?
Of course is meaningful to me, It would be meaningful for anybody that have read what means those results.

help(proc.time)

Description

proc.time determines how much real and CPU time (in seconds) the currently running R process has already taken.

Details

proc.time returns five elements for backwards compatibility, but its print method prints a named vector of length 3. The first two entries are the total user and system CPU times of the current Rprocess and any child processes on which it has waited, and the third entry is the ?real? elapsed time since the process was started.
Rolando Valdez
#
I found a partial solution, I tried with X11(type=?cairo?) and reduced substantially the time plotting
user  system elapsed 
  2.166   0.510   3.604