To get a quick overview of the spatial distribution of smaller data-sets it may be useful to display numeric values as colored boxes.
Such an output may also be referred to as heatmap (note that the term 'heatmap' is frequently associated with graphical display of hierarchcal clustering results).
The function image
provides the basic support to do so (ie heatmap without rearranging rows and columns by clustering).
To do this more conveniently, the function imageW
offers additional options for displaying row- and column-names or displaying NA-values as custom-color.
imageW(
data,
latticeVersion = FALSE,
transp = TRUE,
NAcol = "grey95",
tit = NULL,
rowNa = NULL,
colNa = NULL,
xLab = NULL,
yLab = NULL,
las = 2,
col = NULL,
nColor = 9,
balanceCol = TRUE,
gridCol = "grey75",
gridLty = 1,
centColShift = 0,
cexDispl = NULL,
panel.background.col = "white",
supLat = list(),
rotXlab = 0,
rotYlab = 0,
cexXlab = 0.7,
cexAxs = NULL,
cexYlab = 0.9,
Xtck = 0,
Ytck = 0,
cexTit = 1.6,
silent = FALSE,
debug = FALSE,
callFrom = NULL
)
This function plots in image (to the current graphical device) as image
does
(matrix or data.frame) main input
(logical) use lattice for plotting (this will include a color-legend)
(logical) decide if data should get transposed (if TRUE
the data will be displayed exacetly same order as when printing the values as table);
set to FALSE
to get behaviour prior to version 1.3.0.
(character or integer) custom color for NA-values, default is light grey
(character) custom figure title
(character) optional custom rownames
(character) optional custom colnames
(character) optional custom text for x-axis 'values'
(character) optional custom text for y-axis 'values'
(numeric) style of axis labels (see also par
); in case of latticeVersion=TRUE
this argument will override default rotXlab=0
and/or rotYlab=0
(character or integer) colors; in lattice version 2 or 3 color-names to define central- and end-points of gradient (starting with color for lowest values, optional central color and color for highest values), default is 60 shades 'RdYlBu' RColorBrewer, if 'heat.colors' use heat.colors in min 15 shades
(integer, only used in lattice version) number of color-blocks in color gradient (made based on central- and end-points from col
(logical, only used in lattice version) if TRUE
the color-radient aims to color the value closest to 0 with the center color (from col
(default gray)
(character, only used in lattice version) define color of grid
(integer, only used in lattice version) define line-type of grid (see also lty par
)
(integer, only used in lattice version) shift central (default grey) color element for negative scale up or down (ie increase or reduce number of color-blocks for negatve values), used for correcting automatic scaling rounding issues to ensure the central elements captures 0
(numeric, length=1, only used in lattice version) define cex size for displaying (rounded) values in plot, set to NULL
for omitting
(character, only used in lattice version)
(list, only used in lattice version) additional arguments/parameters passed to levelplot
(numeric, 0 - 360, lattice version only) control rotation of x-axis labels
(numeric, 0 - 360, lattice version only) control rotation of y-axis labels
(numeric) cex-like expansion factor for x-axis labels (see also par
)
(numeric) cex-like expansion factor for x- and y-axis text/labels (see also par
)
(numeric) cex-like expansion factor for y-axis labels (see also par
)
(numeric or logical) expansion factor for length of tick-marks on x-axis (default=0 for no tick-marks)
(numeric or logical) expansion factor for length of tick-marks on y-axis
(numeric) cex-like expansion factor for title (see also par
)
(logical) suppress messages
(logical) additional messages for debugging
(character) allow easier tracking of messages produced
This function allows two modes of operation : 1) plotting using standard R -graphics or 2) using the framework of grid- and lattice-graphics (since version 1.2.6).
The latter version allows integrating a legend for the color-scale and adding grid-lines, rotation of axis-labels or removing tick-marks.
Please note that sometimes the center-color segment may not end up directly with the center-color, in this case you may adjust using the argument centColShift=-1
imageW(as.matrix(iris[1:40,1:4]), transp=FALSE, tit="Iris (head)")
imageW(as.matrix(iris[1:20,1:4]), latticeVersion=TRUE, col=c("blue","red"),
rotXlab=45, yLab="Observation no", tit="Iris (head)")
Run the code above in your browser using DataLab