symbols in spplot
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)
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no