Version: | 2.1.3 |
Date: | 2025-02-04 |
Title: | Plot Stacked Areas and Confidence Bands as Filled Polygons |
Imports: | graphics, grDevices, stats |
Suggests: | MASS |
Description: | Plot stacked areas and confidence bands as filled polygons, or add polygons to existing plots. A variety of input formats are supported, including vectors, matrices, data frames, formulas, etc. |
License: | GPL-3 |
URL: | https://github.com/arni-magnusson/areaplot |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-02-04 02:27:35 UTC; arnim |
Author: | Arni Magnusson [aut, cre] |
Maintainer: | Arni Magnusson <thisisarni@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-02-04 03:30:06 UTC |
Plot Stacked Areas and Confidence Bands as Filled Polygons
Description
Plot stacked areas and confidence bands as filled polygons, or add polygons to existing plots. A variety of input formats are supported, including vectors, matrices, data frames, formulas, etc.
Details
Plot:
areaplot | stacked area |
confplot | confidence band |
Author(s)
Arni Magnusson.
See Also
Useful links:
Area Plot
Description
Produce a stacked area plot, or add polygons to an existing plot.
Usage
areaplot(x, ...)
## Default S3 method:
areaplot(x, y = NULL, prop = FALSE, rev = FALSE,
add = FALSE, xlab = NULL, ylab = NULL, border = NULL, col = NULL,
legend = FALSE, args.legend = NULL, ...)
## S3 method for class 'formula'
areaplot(formula, data, subset, na.action, xlab = NULL,
ylab = NULL, ...)
Arguments
x |
a numeric vector of x values, or if |
... |
further arguments passed to |
y |
a numeric vector of y values, or a matrix containing y values in columns. |
prop |
whether data should be plotted as proportions, so stacked areas equal 1. |
rev |
whether to plot the stacked areas from bottom to top, instead of top to bottom. |
add |
whether polygons should be added to an existing plot. |
xlab |
a label for x axis. |
ylab |
a label for y axis. |
border |
border color of polygon(s). The default is to draw borders in
the foreground color. Pass |
col |
fill color of polygon(s). The default is a vector of gray colors. |
legend |
a logical indicating whether a legend should be added, or a vector of strings for the legend. This only applies when more than one series is plotted. |
args.legend |
a list of additional arguments to pass to the
|
formula |
a |
data |
a data frame (or list) from which the variables in formula should be taken. |
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function which indicates what should happen when the data
contain |
Value
Matrix of cumulative sums that was used for plotting.
See Also
polygon
is the underlying function used to draw polygons.
confplot
plots confidence bands as a filled area.
areaplot-package
gives an overview of the package.
Examples
areaplot(rpois(10,40))
areaplot(rnorm(10))
# formula
areaplot(Armed.Forces~Year, data=longley)
areaplot(cbind(Unemployed,Armed.Forces)~Year, data=longley)
areaplot(.~Year, data=longley)
areaplot(circumference~age+Tree, Orange)
# add=TRUE
plot(1940:1970, 500*runif(31), ylim=c(0,500))
areaplot(Armed.Forces~Year, data=longley, add=TRUE)
# data frame
mydata <- longley[c("Year","GNP")]
areaplot(mydata)
# matrix
areaplot(WorldPhones)
areaplot(WorldPhones, prop=TRUE)
# table
require(MASS)
areaplot(table(Aids2$age))
areaplot(table(Aids2$age, Aids2$sex))
# ts/mts
areaplot(austres)
areaplot(Seatbelts[,c("drivers","front","rear")],
ylab="Killed or seriously injured")
abline(v=1983+1/12, lty=3)
# POSIXt and Date
airquality$Time <- ISOdate(1973, airquality$Month, airquality$Day)
airquality$Date <- as.Date(airquality$Time)
areaplot(Wind~Time, airquality, col="skyblue")
areaplot(Wind~Date, airquality, col="linen")
# border=NA
areaplot(circumference~age+Tree, Orange)
areaplot(circumference~age+Tree, Orange, border=NA)
# legend
require(MASS)
areaplot(table(Aids2$age, Aids2$sex), legend=TRUE, col=c(2,4))
areaplot(table(Aids2$age, Aids2$sex), legend=TRUE, col=c(2,4), rev=TRUE)
wp <- WorldPhones[,order(colnames(WorldPhones))]
areaplot(wp, col=2:8, legend=TRUE, args.legend=list(x="topleft"))
areaplot(wp, col=2:8, legend=TRUE, args.legend=list(x="topleft"), rev=TRUE)
Plot Confidence Band
Description
Plot a confidence band of lower and upper y values as a filled area, or add polygon to an existing plot.
Usage
confplot(x, ...)
## Default S3 method:
confplot(x, y1 = NULL, y2 = NULL, add = FALSE,
xlab = NULL, ylab = NULL, border = NA, col = "lightgray", ...)
## S3 method for class 'formula'
confplot(formula, data, subset, na.action = NULL, ...)
Arguments
x |
a numeric vector of x values. Alternatively, |
... |
further arguments passed to |
y1 |
a numeric vector of lower y values. Alternatively, |
y2 |
a numeric vector of upper y values, if not already supplied in
|
add |
whether the confidence band should be added to an existing plot. |
xlab |
a label for x axis. |
ylab |
a label for y axis. |
border |
border color of polygon. The default |
col |
fill color of polygon. |
formula |
a |
data |
a data frame (or list) from which the variables in formula should be taken. |
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function which indicates what should happen when the data
contain |
Value
Data frame of coordinates that were used for plotting.
See Also
polygon
is the underlying function used to draw polygons.
areaplot
produces a stacked area plot.
areaplot-package
gives an overview of the package.
The gplots and plotrix packages provide functions to plot error bars.
Examples
model <- lm(log(dist)~log(speed), cars)
ci95 <- predict(model, data.frame(speed=4:25), interval="confidence")
ci50 <- predict(model, data.frame(speed=4:25), interval="confidence", level=0.5)
x <- log(4:25)
y1 <- ci95[,"lwr"]
y2 <- ci95[,"upr"]
mydata <- data.frame(x, y1, y2)
# Input format
confplot(x, y1, y2) # vectors
confplot(x, cbind(y1,y2)) # y values in 2 columns
confplot(mydata) # data in 3 columns
confplot(cbind(y1,y2)~x, mydata) # formula
# Overlay
plot(log(dist)~log(speed), cars, type="n")
confplot(x, ci95[,2:3], add=TRUE)
confplot(x, ci50[,2:3], add=TRUE, col="darkgray")
lines(x, ci95[,1])
points(log(dist)~log(speed), cars)