[R] make an own (different) color legend with spplot()
Dieter Menne
dieter.menne at menne-biomed.de
Fri Mar 4 18:52:56 CET 2011
Marcel J. wrote:
>
>
> Is there a way to manually costumize the color legend in an spplot() -
> especially where to draw ticks and labels for the ticks?
>
spplot calls levelplot, so the documentation there gives some help. In
theory, the simplest approach would be to add a colorkey/ticknumber
combination as shown below, but it's always a bit of trial-and-error what
works. In similar cases, I have been bitten several times in the past by
believing the whole approach is wrong, when only certain combinations don't
work.
In the example, setting the width of the legend works, but trying to
position it with space="right" fails, and tick.number alone also. Setting
the items by hand, works. You will probably find a better labeling, I only
added the hx to show you how-to.
Dieter
library(sp)
data(meuse.grid)
gridded(meuse.grid) = ~x+y
meuse.grid$random <- rnorm(nrow(meuse.grid), 7, 2) # generate random data
meuse.grid$random[meuse.grid$random < 0] <- 0 # make sure there is no
meuse.grid$random[meuse.grid$random > 10] <- 10 # and bigger than ten
meuse.grid$random <- cut(meuse.grid$random, seq(0, 10, 0.1)) # here I
labelat = seq(0,100,by=10)
labeltext = paste("Hx",labelat)
spplot(meuse.grid, c("random"), col.regions = rainbow(100, start = 4/6,
end = 1),
colorkey=list(width=0.3, # works
space="right", # not honoured
tick.number=5, # not honoured, can be left out
labels=list( # so we must do it by hand
at=labelat,
labels=labeltext )))
--
View this message in context: http://r.789695.n4.nabble.com/make-an-own-different-color-legend-with-spplot-tp3335552p3335690.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list