[R-sig-Geo] Mapping a factor

Bjarke Christensen Bjarke.Christensen at sydbank.dk
Wed May 5 09:11:40 CEST 2010


Roberto,

I think the following expression is incorrect:
col = colours[findInterval(gino, levels(gino), all.inside = FALSE)]

It should probably just be colours[gino]. You can test that by typing:
data.frame(gino, colours[findInterval(gino, levels(gino), all.inside =
FALSE)], colours[gino])


----
Dear All,

I'm having trouble mapping the levels of a factor.
This is the code I have as of now. The legend works fine (suggesting that
item "colours" is correct), but not the map!

gino = factor(data_abs1$Ethnic.Dominance, labels = c(" French", " German",
"
Italian", " Portuguese", " Spanish", " Fmr. Yugoslavian", " Turkish"))
colours = rev(bpy.colors(n = length(levels(gino)), cutoff.tails = 0.2))
submap <- swiss.map[data_abs$FORACTIVE >=5 & data_abs$NAME != "D?moret",] #

this is only to build a smaller map which excludes some regions
plot(swiss.map, axes = FALSE)
plot(submap, add = TRUE, col = colours[findInterval(gino, levels(gino),
all.inside = FALSE)])
legend("topleft", xjust = 0, ncol = 1, legend = levels(gino), fill =
colours, bty ="n", title = "CIAO")


Can anyone clear the problem?

Thanks a lot
Roberto

********************
Roberto Patuelli, Ph.D.
Istituto Ricerche Economiche (IRE) (Institute for Economic Research)
Universit? della Svizzera Italiana (University of Lugano)
via Maderno 24, CP 4361
CH-6904 Lugano
Switzerland
Phone: +41-(0)58-666-4166
Fax: +39-02-700419665
Email: roberto.patuelli at usi.ch
Homepage: http://www.people.lu.unisi.ch/patuellr



More information about the R-sig-Geo mailing list