Skip to content
Prev 10527 / 29559 Next

Continuous colorbar legend for a SpatialPointsDataFrame object

Hey Piero,

My solution was to use the ggplot2 package. See the example below.

Cheers,

Pierre

# I don't have any R install handy here - I hope this example will run...
library(sp)
library(ggplot2)

data(meuse)
coordinates(meuse) <- ~x+y
# some geospatial operations on meuse here

meuse.df <- as.data.frame(meuse)
my.plot <- ggplot(data=meuse.df, aes(x=x, y=y)) +
geom_point(aes(colour=log(zinc))) + coord_equal()
print(my.plot)

# you can play with the color ramp - the RColorBrewer package is handy for that
library(RColorBrewer)
my.plot <- my.plot + scale_colour_gradientn('name of the legend',
brewer.pal(n=5, 'OrRd'))
print(my.plot)

2010/12/21 piero campa <piero.campa at gmail.com>: