imageByColors | R Documentation |
Display color raster image using a matrix of colors
imageByColors(
x,
useRaster = FALSE,
fixRasterRatio = TRUE,
maxRatioFix = 100,
xaxt = "s",
yaxt = "s",
doPlot = TRUE,
cellnote = NULL,
cexCellnote = 1,
srtCellnote = 0,
fontCellnote = 1,
groupCellnotes = TRUE,
groupBy = c("column", "row"),
groupByColors = TRUE,
adjBy = c("column", "row"),
adjustMargins = FALSE,
interpolate = getOption("interpolate", TRUE),
verbose = FALSE,
xpd = NULL,
bty = par("bty"),
flip = c("none", "y", "x", "xy"),
keepTextAlpha = FALSE,
doTest = FALSE,
add = FALSE,
...
)
x |
matrix or data.frame containing colors |
useRaster |
logical sent to |
fixRasterRatio |
logical sent to |
maxRatioFix |
numeric sent to |
xaxt , yaxt |
character values compatible with |
doPlot |
logical whether to create a plot, or simply return data which would have been used to create the plot. |
cellnote |
matrix or data.frame of labels to be displayed on the
image. If groupCellnotes==TRUE labels will be placed in the center
of consecutive cells with the same label and identical color.
Currently, cell text is colored using |
cexCellnote , srtCellnote , fontCellnote |
numeric vectors, with values
applied to cellnote text to be compatible with par("cex"), par("srt"),
and par("font"), respectively. If supplied a matrix or data.frame with
it is used as-is or expanded to equivalent dimensions of |
groupCellnotes |
logical whether to group labels where consecutive cells contain the same label and identical cell colors, thus only displaying one label in the center of these groups. |
groupBy |
character value indicating the direction to group
cellnotes, when |
groupByColors |
logical indicating whether the cellnote grouping
should also include the cell color. When |
adjBy |
character value indicating how to apply adjustments for cexCellnote, srtCellnote, and fontCellnote, as described above. |
adjustMargins |
logical indicating whether to adjust the axis label margins to ensure enough room to draw the text rownames and colnames. |
interpolate |
logical whether to implement image interpolation, by default TRUE when useRaster=TRUE. |
verbose |
logical whether to print verbose output. |
xpd |
NULLL or logical used for |
keepTextAlpha |
logical passed to |
doTest |
logical whether to run a test showing basic features of
|
This function is similar to image
except that
it takes a matrix which already has colors defined for each cell.
This function calls imageDefault
which enables updated
use of the useRaster
functionality.
Additionally, if cellnote
is supplied, which contains a matrix
of labels for the image cells, those labels will also be displayed.
By default, labels are grouped, so that only one label is displayed
whenever two or more labels appear in consecutive cells. This behavior
can be disabled with groupCellnotes=FALSE.
The groupCellnotes
behavior uses breaksByVector()
to
determine where to place consecutive labels, and it applies this logic
starting with rows, then columns. Note that labels are only grouped when
both the cell color and the cell label are identical for consecutive
cells.
In general, if a large rectangular set of cells contains the same label, and cell colors, the resulting label will be positioned in the center. However, when the square is not symmetric, the label will be grouped only where consecutive columns contain the same groups of consecutive rows for a given label.
It is helpful to rotate labels partially to prevent overlaps, e.g. srtCellnote=10 or srtCellnote=80.
To do:
Detect the size of the area being labeled and determine whether to rotate the label sideways.
Detect the size of the label, compared to its bounding box, and resize the label to fit the available space.
Optionally draw border around contiguous colored and labeled polygons. Whether to draw border based only upon color, or color and label, or just label... it may get confusing.
Label proper contiguous polygons based upon color and label, especially when color and label are present on multiple rows and columns, but not always the same columns per row.
Other jam plot functions:
adjustAxisLabelMargins()
,
coordPresets()
,
decideMfrow()
,
drawLabels()
,
getPlotAspect()
,
groupedAxis()
,
imageDefault()
,
minorLogTicksAxis()
,
nullPlot()
,
plotPolygonDensity()
,
plotRidges()
,
plotSmoothScatter()
,
shadowText_options()
,
shadowText()
,
showColors()
,
smoothScatterJam()
,
sqrtAxis()
,
usrBox()
a1 <- c("red4","blue")[c(1,1,2)];
b1 <- c("yellow","orange")[c(1,2,2)];
c1 <- c("purple","orange")[c(1,2,2)];
d1 <- c("purple","green4")[c(1,2,2)];
df1 <- data.frame(a=a1, b=b1, c=c1, d=d1);
# default using polygons
imageByColors(df1, cellnote=df1);
# useRaster=TRUE, edges are slightly blurred with small tables
imageByColors(df1, cellnote=df1, useRaster=TRUE);
# some text features, rotation, font size, etc
imageByColors(df1, cellnote=df1, useRaster=TRUE, adjBy="column",
cexCellnote=list(c(1.5,1.5,1), c(1,1.5), c(1.6,1.2), c(1.6,1.5)),
srtCellnote=list(c(90,0,0), c(0,45), c(0,0,0), c(0,90,0)));
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.