[R-sig-Geo] SpatialPolygonsDataFrame visualization

Mathieu Basille basille at biomserv.univ-lyon1.fr
Thu Feb 21 12:59:37 CET 2008


Dear Roger, Rick, Paul and others on the list,

Thanks for the advice on the use of lattice. Indeed, lattice may not be 
the right approach here. The only one possibility that I could find was 
the use of the 'split' argument to print 1 by 1 the layers I want. 
However, it was not totally satisfactory for several reasons.

Finally, I ended up with a function based on the regular 'plot':

plotsp <- function (x, var = names(x), mar = if (length(var) > 1) c(0,
     0, 2, 0) else c(5.1, 4.1, 4.1, 2.1), mfrow = NULL)
{
     if (!inherits(x, "SpatialPolygonsDataFrame"))
         stop("object of class SpatialPolygonsDataFrame expected")
     if (is.null(mfrow))
         mfrow = n2mfrow(length(var))
     opar <- par(mfrow = mfrow, mar = mar)
     on.exit(par(opar))
     for (i in var) {
         plot(x, col = ifelse(is.na(x at data[, i]), "red", grey(1 -
             rank(as.numeric(x at data[, i]))/length(x at data[, i]))))
         title(i)
         box()
     }
}

This function plots the selected layers (all if none selected) in 
adjacent boxes with levels of grey, and with polygons in red when they 
are associated with NAs. It works on SpatialPolygonsDataFrame, with 
factors or numeric, but can probably be adapted for SpatialPixelsDataFrame.

It is not exactly what I wanted, since I don't have anymore the 
colorkey, but at least I can visualize at once the NA on several layers 
that represent different variables.

Thanks again for the hints,
Mathieu.



Roger Bivand a écrit :
> On Thu, 14 Feb 2008, Mathieu Basille wrote:
> 
>> Thanks Rick for the hints.
>>
>> I have to admit, however, that it is so far a huge failure. I have been
>> able to play a bit with the color key (arg 'colokey' that sets the
>> position, the colors, the tick marks, height & width, etc.) and the
>> color of one map (arg 'col.regions', for finite values of the layer),
>> but I'm still unable to
>> 1) have different scales for different layers (i.e. one color key per
>> layer);
> 
> This suggests that you really should not be using lattice graphics, 
> because they are specifically written for conditional plots, so 
> necessarily on the same scale for comparision
> 
>> 2) color NA with a non-contiguous color from other finite values. From
>> my different tests, NA are always white (I wish I could fill them in red
>> for example, with finite values in a gradient of grey).
>>
>> In addition, I'm totally lost in the help pages of xyplot and levelplot
>> (lattice), and the graph gallery of sp didn't help neither.
>>
>> Any other resource or tutorial for this?
> 
> There is Paul Murrell's R Graphics book (Chapman & Hall/CRC), and 
> lattice author Deepayan Sarkar's forthcoming lattice book (Springer useR 
> series), but lattice is, I think, not what you want if you want to 
> control things yourself. Just use base graphics and build things up 
> layer by layer.
> 
> Lattice is superb for what it is designed for, by the way, say 
> conditioning earthquake location by depth as the classic example, or 
> plotting anisotropic variograms by direction.
> 
> Roger
> 
>> Thanks in advance,
>> Mathieu.
>>
>>
>> Rick Reeves a écrit :
>>> Mathiu:
>>>
>>> The attached use case might help: It is not exactly what you are looking
>>> for, but the last map
>>> demonstrates use of the spplot function to create a 'display list' that
>>> plots vector and raster
>>> data layers on a single map. Also some hints on creating a map scale and
>>> legend.
>>>
>>> http://nceas.ucsb.edu/scicomp/GISSeminar/UseCases/MapProdWithRGraphics/OneMapProdWithRGraphics.html 
>>>
>>>
>>>
>>> Regards,
>>> Rick Reeves
>>>
>>> Mathieu Basille wrote:
>>>> Hello everyone,
>>>>
>>>> I'm not very familiar with visualization of spatial objects in R,
>>>> especially with the possibilities of the spplot function...
>>>>
>>>> I have a SpatialPolygonsDataFrame and I'd like to obtain a map with a
>>>> specific scale for each layer (not in the geographic space, but in the
>>>> data), instead of the same one for every one. In my case, the layers
>>>> represent different variables, not on the same scale (e.g. elevation
>>>> and rain).
>>>>
>>>> Additionally, I'd like to represent NA's with a particular color (say
>>>> black so that we can see immediately where they occur).
>>>>
>>>> I guess these 2 issues are somehow related, but I didn't manage to
>>>> solve them. The help pages of spplot or xyplot didn't really help...
>>>>
>>>> Any hint how to do that?
>>>> Thanks in advance,
>>>> Mathieu.
>>>>
>>>>
>>>> > version
>>>> platform       i486-pc-linux-gnu
>>>> svn rev        43537
>>>> version.string R version 2.6.1 (2007-11-26)
>>>> sp: sp_0.9-19
>>
>>
>>
> 


-- 

¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
                                                 ]
  Mathieu BASILLE -- PhD Student                 ]
                                                 ]
  Laboratoire de Biométrie et Biologie Évolutive ]
  Université Claude Bernard Lyon 1 - France      ]
   http://lbbe.univ-lyon1.fr/                    ]
                                                 ]
  My resume:                                     ]
   http://mathieu.basille.net/pro/               ]
  Habitat web-site:                              ]
   http://biomserv.univ-lyon1.fr/spip_habitat/   ]
________________________________________________]




More information about the R-sig-Geo mailing list