I am creating a map using tmap with a quantitative variable that I wish to use for setting the polygon colours. When I set the colour ramp using a standard RColorBrewer palette or with a custom vector of colours, it is only using half of the values in the colour ramp (but I want them all!). For example, with the "RdYlGn" palette, it is only plotting from yellow to green without any reds.
Let's take the example of the
meuse dataset (I am taking the start of this example from this answer (Mapping several maps with the same colorscheme in tmap))
library(sp) library(tmap) library(rgeos) # for the gBuffer function in this example data(meuse, meuse.area) coordinates(meuse) <- ~x + y meuse.area <- SpatialPolygons(list(Polygons(list(Polygon(meuse.area)),'1'))) proj4string(meuse)<- CRS("+init=epsg:28992") proj4string(meuse.area)<- CRS("+init=epsg:28992") #turn it into a spatial polygon for my purposes meuse.poly=gBuffer(meuse, width=100, byid=TRUE) tm_shape(meuse.poly)+ tm_polygons("dist", title="dist", palette="RdYlGn", n=6)
Here's the map with this example:
But I don't get the full spectrum of colours: