Skip to content
Prev 8485 / 29559 Next

Plot categorical data from SpatialPolygonsDataFrame in color with label: plot() vs spplot()

On Thu, Jun 10, 2010 at 10:47 AM, christiaan pauw <cjpauw at gmail.com> wrote:
what's 'xx'? I'll assume you meant 'x' and carry on...
You've not given the text() function a character argument!
x at data$NAME is a factor, so I think text() thinks this is your Y
coordinate. Try:

 > plot(x)
 > text(coordinates(x),x at data$NAME,cex=0.25)
 > text(coordinates(x),as.character(x at data$NAME),cex=0.25)

 the first fails horribly (draws numbers at odd places) but the second works.

 I'm not sure if cex=0.025 works since I don't have an electron
microscope handy in order to read it!  There may be limitations on
very small text sizes with some graphics devices. There certainly is
on my eyes...

 Also, you can probably plot the coloured ones in one go. Something like:

 > mypal = c("green","grey","brown","red")
 > plot(my.select,col=mypal[my.select$cat])

there are other ways of mapping values to colours, such as my
colourschemes package [shameless plug!], but this is the simplest.

hope that helps

Barry