plotMatrix {survSpearman} | R Documentation |
Plots a color matrix.
Description
Plots a matrix of colors at a given point. Each element of the color matrix is plotted as a rectangle with user specified side lengths and border color.
Usage
plotMatrix(colorMatr, borderCol, coordX, coordY, widthX, widthY)
Arguments
colorMatr |
A matrix of colors in R format. |
borderCol |
The border color of plotted rectangles. |
coordX |
X coordinate of the lower left corner of |
coordY |
Y coordinate of the lower left corner of |
widthX |
The vector of lengths of the rectangle sides parallel to the X-axis. The length of |
widthY |
The vector of lengths of the rectangle sides parallel to the Y-axis. The length of |
Details
R
-function plot()
has to be called first. The function plots a color matrix at a given coordinate. Each element of the color matrix is plotted as a rectangle with user specified border color and side lengths on X- and Y-axes. Element colorMatr[nrow(colMatr), 1]
is displayed as the bottom left rectangle. Element colorMatr[1, ncol(colMatr)]
is displayed as the top right rectangle.
Value
None
Author(s)
Svetlana K Eden, svetlanaeden@gmail.com
Examples
### Uneven rectangles
colorMatr = matrix(c("goldenrod1", "mediumpurple3", "palegreen3",
"royalblue1", "orchid", "firebrick1"), nrow = 2, byrow = TRUE)
plot(c(1, 4), c(2, 4), type = "n", xlab = "", ylab = "")
plotMatrix(colorMatr, borderCol = "white", coordX = 1, coordY = 2,
widthX = c(1/4, 1, 1/6), widthY = c(1, 1/2))
### Plotting the legend:
reshapeColMatr = matrix(t(colorMatr), ncol = 1, nrow = nrow(colorMatr)*ncol(colorMatr),
byrow = TRUE)
plotMatrix(reshapeColMatr, borderCol = "white", coordX = 2.8, coordY = 2,
widthX = c(1/4), widthY = c(1/4))
text(x = rep(3.03, nrow(reshapeColMatr)),
y = 2.12+c(0,cumsum(rep(1/4, nrow(reshapeColMatr)-1))),
labels = reshapeColMatr[nrow(reshapeColMatr):1], pos = 4, cex = 0.7)
### Same length and width rectangles on the black background
plot(c(1, 4), c(2, 4), type = "n", xlab = "", ylab = "")
polygon(x = c(0, 5, 5, 0, 0), y = c(0, 0, 5, 5, 0), col = "black")
plotMatrix(colorMatr, borderCol = "black", coordX = 1, coordY = 2, widthX = 1, widthY = 1)