colourScale {mapmisc} | R Documentation |
Produces a scale of colours for plotting maps
colourScale(x, breaks=5, style=c("quantile","equal","unique", "fixed"), col="YlOrRd", opacity=1, dec=NULL, digits = 6, firstBreak=NULL, transform=NULL, revCol=FALSE, exclude=NULL, labels=NULL, ...) colorScale(...) breaksForRates(x, breaks = 10, transform = 0.1, multiples = c(2, 4, 5, 10))
x |
A vector or single-layer Raster, numeric or factor, for which a colour scale will be created |
breaks |
For |
style |
Style for breaks, see Details |
col |
Colours to use, either a function or
argument for |
opacity |
adds transparency to colours, either a single number,
vector of length 2, or vector of same length as |
dec |
Number of decimal places for the breaks |
digits |
Number of significant figures |
firstBreak |
If non-null, force the first break to take this value (often zero). |
transform |
A list of two functions to transform |
revCol |
Reverse the order of the colours. |
exclude |
A vector of values to change to NA when they appear in |
labels |
Vector of names of levels, useful when |
multiples |
break points must be multiples of these numbers times a power of 10 |
... |
Additional arguments passed to |
colourScale
produces intervals from x
, each with a unique colour. Categories are determined with break points according to the following style
options:
quantile
: quantile(x, prob=seq(0,1,len=breaks), )
equal
: seq(min(x), max(x), len=breaks)
unique
: sort(table(unique(x)))[1:breaks]
fixed
: breaks
any other string: is passed to classIntervals
colorScale
passes all it's arguments to colourScale
breaksForRates
returns break points suitable for mapping incidence rates, which are positive and always
include 1.0.
A list with elements
plot |
Vector of same length of |
breaks |
vector of break points |
col |
vector of unique colour values corresponding to |
colWithOpacity |
as |
legendBreaks
,scaleBar
, classIntervals
breaksForRates(13.6, breaks = 7) Npoints = 20 myPoints = SpatialPointsDataFrame(20*cbind(runif(Npoints), runif(Npoints)), data=data.frame(y1=c(NA, rnorm(Npoints-1)), y2=c(sample(1:4, Npoints-1,replace=TRUE), NA)), proj4string=mapmisc::crsLL) ## Not run: mymap = openmap(myPoints) ## End(Not run) if(require('RColorBrewer', quietly=TRUE)) { theCol = 'RdYlBu' } else { theCol = heat.colors } myscale = colourScale(myPoints$y1, breaks=4, col=theCol, style="quantile", revCol=TRUE,dec=1) map.new(myPoints) ## Not run: plot(mymap,add=TRUE) ## End(Not run) plot(myPoints, col=myscale$plot, pch=16,add=TRUE) legendBreaks("topleft", breaks=myscale) myscale2 = colourScale(myPoints$y1, breaks=8, col=rainbow, style="equal", opacity=0.8, dec=2, revCol=TRUE) map.new(myPoints) ## Not run: plot(mymap,add=TRUE) ## End(Not run) plot(myPoints, col=myscale2$plot, pch=16,add=TRUE) legendBreaks("topleft", breaks=myscale2) if(require('RColorBrewer', quietly=TRUE)) { theCol = 'Set2' } else { theCol = heat.colors } myscale3 = colourScale(myPoints$y2, breaks=3,col=theCol, style="unique", opacity=c(0.1, 0.9)) map.new(myPoints) ## Not run: plot(mymap,add=TRUE) ## End(Not run) plot(myPoints, col=myscale3$plot, pch=16,add=TRUE) legendBreaks("topleft", breaks=myscale3) myPoints$y3 = exp(myPoints$y1) myscale4 = colourScale(myPoints$y3, breaks=4, style="equal", opacity=c(0.1, 0.9), transform=1.25,dec=0, firstBreak=0) map.new(myPoints) ## Not run: plot(mymap,add=TRUE) ## End(Not run) plot(myPoints, col=myscale4$plot, pch=16,add=TRUE) legendBreaks("topleft", legend=myscale4$breaks, col=myscale4$col)