Learn R Programming

magicaxis (version 1.6)

magmap: Value remapper

Description

This function allows the use to remap a vector of values onto a different system. For instance you might have values stretching from -10 to 100 which you want mapped from 0 to 2/3 so you can then sue the output as an input for point colour or size. It allows clipping of values, rejection of bad values, and log stretching.

Usage

magmap(data, lo = 0, hi = 1, flip = FALSE, range = c(0, 2/3), type = "quan",
log = FALSE, bad = NA)

Arguments

data
A vector of values. This can contain bad values (NA, NaN, infinite), but these will be ignored during mapping and set to the value of input paramter 'bad'.
lo
The low limit to clip the data at (what this means varies depending on the 'type' option.
hi
The high limit to clip the data at (what this means varies depending on the 'type' option.
flip
Should the scaling be flipped. This allows numbers from 0 to 10 to be mapped from 1 to 0 (so ordered back to front with respect to the input).
range
The range of the output mapping.
type
The type of mapping attempted. Options are 'quan' (default), 'num', 'sig' and 'rank'. 'quan' means the lo and hi options are interpreted as the quantile limits to clip the data at (so lo=0.05 and hi 0.95 would clip the data at the 5% and 95% quantile limi
log
If TRUE log mapping is used. If range is 1 and 100 and log=FALSE the midpoint in the mapping will be 50.5, if log=TRUE the midpoint becomes 10. This enhances the local dynamic range of the mapping for data that has a logarithmic distribution.
bad
Sets the value that NA, NaN and infinite input data should be set to.

Value

  • mapThe remapped data. This is the same length and order as the input data.
  • datalimThe a vector of the low and high limits actually applied to the data. Unless type='num' this will probably be different to 'lo' and 'hi'.
  • maplimThe output range (same is the requested input range, but included for book-keeping).
  • loclipThe number of objects clipped from the input data at the low end.
  • hiclipThe number of objects clipped from the input data at the high end.

Examples

Run this code
temp=cbind(runif(100),runif(100))
temp=cbind(temp,sqrt(temp[,1]^2+temp[,2]^2))
magplot(temp)
magplot(temp[,1:2],col=hsv(h=magmap(temp[,3])$map))
# A different mapping type:
magplot(temp[,1:2],col=hsv(h=magmap(temp[,3],type='rank')$map))
# Flipped:
magplot(temp[,1:2],col=hsv(h=magmap(temp[,3],flip=TRUE,type='rank')$map))
# Example of log mapping:
temp=cbind(temp,10^temp[,3])
magplot(temp[,1:2],col=hsv(h=magmap(temp[,4])$map))
magplot(temp[,1:2],col=hsv(h=magmap(temp[,4],log=TRUE)$map))
#Combination of mapping:
magplot(temp[,1:2],col=hsv(h=magmap(temp[,4],log=TRUE)$map),
cex=magmap(temp[,3],lo=0.5,hi=1,range=c(1,6),type='num')$map)

Run the code above in your browser using DataLab