[R-SIG-Mac] Dramatically slow map plotting

peter dalgaard pdalgd at gmail.com
Fri Mar 21 13:04:48 CET 2014


On 21 Mar 2014, at 08:15 , David Winsemius <dwinsemius at comcast.net> wrote:

> 
> On Mar 20, 2014, at 4:56 PM, Rolando Valdez wrote:
> 
>> 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()
> 
> Most people use system.time and not proc.time.
> 
> When you execute proc.time you get something like:
> 
>> proc.time()
>     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 

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

I get:

> system.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
+ 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.

> 
> -- 
> David.
> 
>> 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
>> 
>> _______________________________________________
>> R-SIG-Mac mailing list
>> R-SIG-Mac at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> 
> David Winsemius
> Alameda, CA, USA
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-SIG-Mac mailing list