[R-sig-Geo] Mapping a factor
Roberto Patuelli
roberto.patuelli at usi.ch
Mon May 3 19:02:57 CEST 2010
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