ribbon | R Documentation |
A slight modification to polygon
with quality of life improvements to make it easier to add colored confidence
intervals to a plot. Default values are taken for all
polygon
arguments, except for border
, which
is set to NA
. Additionally, an alpha
argument has been added to
accommodate partially transparent confidence intervals. Any of the input values
can be overwritten within this function's call.
ribbon( x, y, density = NULL, angle = 45, border = NA, col = NA, lty = par("lty"), ..., fillOddEven = FALSE, alpha = NULL )
x |
vector containing the x-axis coordinates of the polygon vertices. See details for more information.. |
y |
Either a vector containing the y-axis coordinates of the polygon vertices, or a two column data.frame / matrix with the vertices. See details for more information. |
density |
Set to |
angle |
Set to |
border |
Set to |
col |
Set to |
lty |
Set to |
... |
Additional arguments such as |
fillOddEven |
Set to |
alpha |
new alpha level in [0,1]. If |
If y
is a two column data.frame or matrix, ribbon
will convert y
to a vector
such that y = c(y[,1], rev(y[,2]))
in order to create the lower and upper bounds of
the polygon. Additionally, when y
is a two column data.frame or matrix, x
can have the same
length as the number of rows in y
, and ribbon
will concatenate the reverse of the
vector x
to ensure it has equal length.
## Not run: # Load data data(cars) # fit model m1 <- lm( dist ~ speed, data = cars ) # make predictions preds <- predict( m1, newdata = data.frame(speed = 10:25), interval = "confidence" ) # base plot blank( xlim = c(10,25), ylim = c(15,120), xlab = "Speed", ylab = "Stopping distance", xaxt = "s", yaxt = "s", bty = "l", las = 1 ) # add 95% confidence interval ribbon( x=10:25, y=preds[,c("lwr","upr")], col = "purple", alpha = 0.5 ) # add mean prediction lines( x=10:25, y = preds[,"fit"], lwd =2, col = "purple" ) # add data points( x = cars$speed, y = cars$dist, pch = 16 ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.