DescTools (version 0.99.18)

Shade: Produce a Shaded Curve

Description

Sometimes the area under a density on a graphic has to be color shaded, for instance to illustrate a p-value or a region under the normal curve. This function offers a function interface for doing this with less code.

Usage

Shade(FUN, col = par("fg"), xlim, density = 10, step = 0.01, ...)

Arguments

FUN
the function to be evaluated, best given as text: FUN="f(x)".

col
color to fill or shade the shape with. The default is taken from par("fg").

xlim
range of the x-range.

density
the density of the lines as needed in polygon.

step
the step for the x-values to be used for calculating the function values.

...
the dots are passed on to polygon.

Value

Details

Useful for shading the area under a curve as often needed for explaining significance tests.

See Also

polygon

Examples

Run this code
curve(dt(x, df=5), xlim=c(-6,6),
      main=paste("Student t-Distribution Probability Density Function, df = ", 5, ")", sep=""),
      type="n", las=1, ylab="probability", xlab="t")

Shade(FUN="dt(x, df=5)", xlim=c(-6, qt(0.025, df=5)), col="red")
Shade(FUN="dt(x, df=5)", xlim=c(qt(0.025, df=5), qt(0.975, df=5)), col="green")
Shade(FUN="dt(x, df=5)", xlim=c(qt(0.975, df=5), 6), col="red")

Run the code above in your browser using DataCamp Workspace