[R-sig-Geo] symbols in spplot

Peter van Horssen p.w.van.horssen at buwa.nl
Thu Feb 5 10:37:17 CET 2009


Thanks Roger,

your trick worked, reworking the polygon data to a raster and plotting 
the file with image()
and then plotting the rest with plot(...., add=TRUE) works great (see 
attached code).
It shows that the famous KISS principle (keep is simple, stupid ) also 
applies to plotting maps
in R .......

Peter

## code
image(rasterdata["n"], col=colors)
plot(radarcirkels, add=TRUE)
plot(circle2, add= TRUE)
plot(turbines, pch=18, add= TRUE, col = 'red')
plot(metmast, pch = 19, col = 'blue', add= TRUE)
plot(raster,pch=my.symbols(raster.midpoint$raster.mid.x1,raster.midpoint$raster.mid.x2,
      ms.arrows, angle= Data$rad, inches=0.5, adj=0.5, lwd=1.5, code = 
2, col = 'blue'), lty="blank",
    add=TRUE)
##code

Roger Bivand schreef:
> On Wed, 4 Feb 2009, Peter van Horssen wrote:
>
>> Dear all,
>>
>> I have a plot problem which is related to the 'contourlines on a plot 
>> question' from a while ago.
>>
>> I have a  map with 144 polygons (squares), for each square we 
>> calculate the mean flight direction (of birds).
>> What I try to plot is a map with the samplesize as a
>> greyscale in the polgons and an arrow on top depicting the mean 
>> direction of that square.
>> The polygonmap with greyscale is easily plotted with spplot.
>> The arrows with mean direction are a bit more difficult. Most sources
>> point towards the 'grid' package or towards arrows(). Both draw arrows
>> with xy pairs (form > to) in graph coordinates.
>> However 'mysymbols' in the library TeachingDemos plots a arrow symbol
>> with a direction 'dir' (in radians) and a fixed length, just what I 
>> need.
>> Unfortunately these arrows only plot with 'plot' command (see 
>> attached code) and therefore do not allign
>> with the plot resulting from ssplot. As you can see  the arrows are 
>> plotted as a pch 'symbol'.
>
> If you try to use only base graphics, you may find this easier to sort 
> out initially - so make the greyscale plot with image() if the data 
> are gridded or plot() if irregular polygons - more intervention will 
> be needed to choose the colours and to provide a legend, then overplot 
> using my.symbols(), which seems to be a base graphics function, if 
> I've found the right one. Otherwise you'll need to find a way to draw 
> the arrows by for example constructing a SpatialLines object of 
> arrows, and using sp.lines in the sp.layout= argument.
>
> Hope this helps,
>
> Roger
>
>>
>> I tried to construct a 'sp.points' element for the sp.layout
>> with the my.symbols ( .....) argument but this doesn't work
>> The arrow.sp$pch is NULL and when I manually force the my.symbol(..) 
>> in it by :
>> ####
>> arrow.sp$pch <- 
>> my.symbols(raster.midpoint$raster.mid.x1,raster.midpoint$raster.mid.x2,ms.arrows, 
>> angle= Data$rad, inches=0.5, adj=0.5, lwd=1.5, code = 2, col = 'blue')
>> ####
>> the spplot command generates an error
>>
>> Question:
>> is there an obvious solution tot this (relative simple) problem ?
>> if not, is there a way to 'allign' de plots from spplot and plot (the 
>> arrowplot) ?
>>
>>
>>
>> thanks in advance
>>
>>
>> ##plot raster##
>> radarcirkels.sp <- list("sp.polygons", radarcirkels)
>> circle2.sp <- list("sp.polygons", circle2, add= TRUE)
>> turbines.sp <- list("sp.points", turbines, pch=18, add= TRUE, col = 
>> red')
>> metmast.sp <- list("sp.points", metmast, pch = 19, col = 'red', add= 
>> TRUE)
>> turbine.radar.layout <- list(radarcirkels.sp, circle2.sp, 
>> turbines.sp, metmast.sp)
>> colors <- shadepalette("darkgreen","white",n=20)
>> spplot (raster1["n"],col.regions=colors,at=c(0,10,50,100,200,300), 
>> sp.layout = turbine.radar.layout)
>>
>> ##plot arrows ##
>> library(TeachingDemos)
>> plot(raster)
>> plot(radarcirkels, add=TRUE)
>> plot(circle2, add= TRUE)
>> plot(turbines, pch=18, add= TRUE, col = 'red')
>> plot(metmast, pch = 19, col = 'blue', add= TRUE)
>> plot(raster,pch=my.symbols(raster.midpoint$raster.mid.x1,raster.midpoint$raster.mid.x2, 
>>
>>     ms.arrows, angle= Data$rad, inches=0.5, adj=0.5, lwd=1.5, code = 
>> 2, col = 'blue'), add=TRUE)
>>
>>
>


-- 
================================
Peter van Horssen
Bureau Waardenburg bv
Adviseurs voor ecologie & milieu
Postbus 365
4100 AJ Culemborg
Tel: 0345-512710
Fax: 0345-519849
e-mail: p.w.van.horssen at buwa.nl
================================

---------------------------- DISCLAIMER -------------------------- 
De informatie verzonden met dit e-mail bericht is uitsluitend bestemd voor de geadresseerde. Openbaarmaking, vermenigvuldiging, verspreiding en/of verstrekking aan derden is niet toegestaan. Gebruik van deze informatie door anderen dan de geadresseerde is verboden. U wordt verzocht bij onjuiste adressering de afzender direct te informeren door het bericht te retourneren.




More information about the R-sig-Geo mailing list