[R-sig-Geo] background colour when add=T

Matthew Landis landis at isciences.com
Thu Sep 13 19:58:32 CEST 2012


Rob -
Without seeing your code, I'm not exactly sure what you are trying to 
do.  But, I routinely control the appearance of land vs. sea with a 
setup something like this:

bg.spdf    # a spatialPolygonsDataFrame with 1 polygon for ocean and 1 
for land
bg.fill  <- c('transparent', 'gray')   # If the wrong one is filled, 
switch order
data.sgdf   # A spatialGridDataFrame of the data I want to plot

spplot(data.sgdf, panel = function(x, y, ...){
         sp.polygons(bg.spdf, fill = bg.fill)
         })

Hope that helps.

M

On 9/13/2012 1:29 PM, Greg Snow wrote:
> One possibility would be to define a spatial polygon that represents
> the entire plotting area, then use the gDifference function from the
> rgeos package to create a map that excludes the land areas (or
> whatever you don't want to cover) and add the resulting polygon(s).
>
> On Thu, Sep 13, 2012 at 8:04 AM, Rob Robinson <rob.robinson at bto.org> wrote:
>> Dear All,
>>   I am trying to plot some abundance density maps for different species
>> of birds which may be either marine or terrestrial. Having created the
>> density kernel (using kde from package ks), I plot() a background map
>> (actually a SpatialPolygonsDataFrame) and I can colour the land and
>> sea differently using col= and bg= options respectively, I can then
>> overlay my kernel using filled.contour. What I would now like to do is
>> mask the inappropriate part of the map. For marine birds this is easy,
>> simply replot the map using add=T and col= to 'blank' out the part of
>> the kernel over land. I thought the same would be true for landbirds,
>> simply use bg= to mask out the sea. Unfortunately when you have add=T
>> plot (not unreasonably, I suppose) doesn't seem to honour the bg=
>> argument, it just (I presume) sets it to 'transparent'. Does anyone
>> know if there is a way to subvert this? A posting from a couple of
>> years ago suggests probably not, but I wondered if anything had
>> changed in the interim?
>> many thanks in advance for any insights...
>> cheers
>> rob
>>
>> **************  Find out about Britain's birds - www.bto.org/birdfacts
>>   **************
>>
>> Dr Rob Robinson, Principal Ecologist
>> British Trust for Ornithology, The Nunnery, Thetford, Norfolk, IP24 2PU
>> Ph: +44 (0)1842 750050     E: rob.robinson at bto.org
>> Fx: +44 (0)1842 750030     W: www.bto.org/about-bto/our-staff/rob-robinson
>>
>> ====== "How can anyone be enlightened, when truth is so poorly lit" =======
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~
Matthew Landis, Ph.D.
Research Scientist
ISciences, LLC
61 Main St. Suite 200
Burlington VT 05401
802.864.2999
www.isciences.com
~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the R-sig-Geo mailing list