Title: | 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. |
Authors: | Arni Magnusson [aut, cre] |
Maintainer: | Arni Magnusson <[email protected]> |
License: | GPL-3 |
Version: | 2.1.1 |
Built: | 2024-11-04 02:46:59 UTC |
Source: | https://github.com/arni-magnusson/areaplot |
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.
Plot:
areaplot |
stacked area |
confplot |
confidence bands |
Arni Magnusson.
Produce a stacked area plot, or add polygons to an existing plot.
areaplot(x, ...) ## Default S3 method: areaplot(x, y = NULL, prop = FALSE, rev = FALSE, add = FALSE, xlab = NULL, ylab = NULL, col = NULL, legend = FALSE, args.legend = NULL, ...) ## S3 method for class 'formula' areaplot(formula, data, subset, na.action, xlab = NULL, ylab = NULL, ...)
areaplot(x, ...) ## Default S3 method: areaplot(x, y = NULL, prop = FALSE, rev = FALSE, add = FALSE, xlab = NULL, ylab = NULL, col = NULL, legend = FALSE, args.legend = NULL, ...) ## S3 method for class 'formula' areaplot(formula, data, subset, na.action, xlab = NULL, ylab = NULL, ...)
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. |
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 |
Matrix of cumulative sums that was used for plotting.
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.
areaplot(rpois(10,40)) areaplot(rnorm(10)) # formula areaplot(Armed.Forces~Year, data=longley) areaplot(cbind(Armed.Forces,Unemployed)~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) # 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)
areaplot(rpois(10,40)) areaplot(rnorm(10)) # formula areaplot(Armed.Forces~Year, data=longley) areaplot(cbind(Armed.Forces,Unemployed)~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) # 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 bands of lower and upper y values as a filled area, or add polygon to an existing plot.
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, ...)
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, ...)
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 confidence bands 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 |
Data frame of coordinates that were used for plotting.
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.
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)
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)