[R-sig-Geo] sp: spplot bug in sp 0.9-2

Edzer J. Pebesma e.pebesma at geo.uu.nl
Tue Oct 17 13:29:40 CEST 2006


Dear spplot users,

When spplot is used with the names.attr argument for label placement in 
the strips, and the names of the variables in zcol are not in alphabetic 
order, strips will receive the wrong name. I found out only now because 
apparently I tend to use names in alphabetic order, or just overlooked 
it. sp 0.9-3 (submitted to CRAN) will fix this, but I'm unhappy with the 
way I fix it.

I believe the example below explains the bug and the unsatisfactory fix.

 > f = factor(c("c","c","b","b","a","a"))
 > f
[1] c c b b a a
Levels: a b c
# and we now want the same data, but with level order c, b, a

# what spmap.to.lev (called from spplot) did was:
 > factor(as.integer(f), labels = c("cc","bb","aa"))
[1] aa aa bb bb cc cc
Levels: cc bb aa

#what we want is (and sp 0.9-3 does) is:
 > factor(as.character(f), levels = c("c","b","a"), labels = 
c("cc","bb","aa"))
[1] cc cc bb bb aa aa
Levels: cc bb aa

which is quite something different. But this will convert a potentially 
huge factor to character and back to factor which may be resource 
intensive. Does anyone here know a simpler way of achieving this, i.e. 
given f, without using as.character()?

Without names.attr, the panel order could be wrong as
 > spplot(meuse.grid, c("part.a", "part.b"))
 > spplot(meuse.grid, c("part.b", "part.b"))
produced the same plot; but with correct strip labels.
The plots are now different in sp 0.9-3.

Bests,
--
Edzer




More information about the R-sig-Geo mailing list