Draws one or several stacked area series using cumulative polygons.
The function accepts either a matrix of values or separate x and
y coordinates. Multiple series are displayed as stacked areas.
Usage
plotArea(
x,
y,
main = NULL,
xlab = "",
ylab = "",
xlim = NULL,
ylim = NULL,
xax = NULL,
yax = NULL,
prop = FALSE,
col = NULL,
border = TRUE,
grid = .useTheme,
legend = TRUE,
stamp = .useTheme,
...
)Arguments
- x
numeric vector, matrix or data frame. If
yis missing,xis interpreted as a matrix of series where rows correspond to x positions and columns to individual areas.- y
optional numeric vector or matrix giving the y-values. If supplied,
xis interpreted as the x-coordinates.- main
main title of the plot.
- xlab
label for the x-axis.
- ylab
label for the y-axis.
- xlim
limits for the x-axis.
- ylim
limits for the y-axis.
- xax, yax
control the x- and the y-axis.
NULL(default) draws the axis with default settings,FALSEsuppresses it. A string is taken as the format of the tick labels,yax = "%"is short foryax = list(fmt = "%"). A named list may mix arguments forfm()(fmt,digits,bigMark, ...) and forgraphics::axis()(las,col,cex, ...), e.g.yax = list(fmt = "%", digits = 0). See Details for a date axis and for row names.- prop
logical indicating whether rows should be converted to proportions so that stacked areas sum to one.
- col
fill colours used for the areas.
- border
controls the line along the upper edge of each area.
TRUE(default) draws a thin line in a darker shade of the area's fill, which keeps neighbouring bands of similar colour apart.FALSE,NULLorNAdraw none. A named list is passed tographics::lines()(col,lwd,lty);colmay be a vector, recycled over the areas, e.g.list(col = "white", lwd = 1.5).- grid
controls the background grid.
.useTheme(default) follows the active theme (getTheme()$grid),TRUEdraws it,FALSE,NULLorNAsuppress it, and a named list is passed tographics::grid().- legend
logical or list controlling the legend. If
TRUE, a legend is drawn using the column names of the data. If a list is supplied, its elements are passed to the internal legend drawing routine.- stamp
controls the corner stamp.
.useTheme(default) resolves togetTheme()$stamp.TRUE/FALSE/NULL, a string, or a named list forstamp().- ...
additional graphical parameters passed to
graphics::par()via.applyParFromDots()and to the plotting functions.
Value
Invisibly returns a list containing:
xthe x-values used for plotting,ythe original y-values,cumulativethe cumulative values used to construct the areas,legendthe legend specification if drawn.
Details
If y is missing, x is interpreted as a matrix and each column
is drawn as a separate stacked area.
The cumulative sums are calculated row-wise and displayed as polygons stacked on top of each other.
If prop = TRUE, each row is converted to proportions before plotting,
so the stacked areas sum to one.
Row names are used as x-axis labels when available and y is omitted.
They are category names, so the format arguments in xax do not apply
to them, its axis() arguments do.
If x is a Date or POSIXct vector, the x-axis ticks fall on
calendar boundaries (years, months, days, ...) and the date patterns of
fm() can be used to label them, e.g. xax = "yyyy".
See also
Other plot.univariate:
plotBar(),
plotBox(),
plotCatDist(),
plotDens(),
plotDensBox(),
plotDot(),
plotECDF(),
plotFreqDist(),
plotLines(),
plotQQ(),
plotRidge(),
plotViolin()
Examples
plotArea(VADeaths)
# white separators instead of the darker edges
plotArea(VADeaths, border = list(col = "white", lwd = 1.5))
plotArea(
WorldPhones,
col = pal("helsana")
)
plotArea(
WorldPhones,
prop = TRUE,
col = rainbow(ncol(WorldPhones)),
yax = list(fmt = "%", digits = 0)
)
x <- 1:20
y <- cbind(
A = runif(20, 1, 5),
B = runif(20, 1, 3),
C = runif(20, 1, 4)
)
plotArea(x, y)
