| type_summary | R Documentation |
y at unique values of xApplies a summary function to y along unique values of x. For example,
plot the mean y value for each x value. Internally,
type_summary() applies a thin wrapper around ave and
then passes the result to type_lines for drawing.
type_summary(fun = mean, ...)
fun |
summarizing function. Should be compatible with
|
... |
Additional arguments are passed to the |
ave which performs the summarizing (averaging) behind the
scenes.
# Plot the mean chick weight over time
tinyplot(weight ~ Time, data = ChickWeight, type = "summary")
# Note: "mean" is the default function, so these are also equivalent:
# tinyplot(weight ~ Time, data = ChickWeight, type = type_summary())
# tinyplot(weight ~ Time, data = ChickWeight, type = type_summary(mean))
# Plot the median instead
tinyplot(weight ~ Time, data = ChickWeight, type = type_summary(median))
# Works with groups and/or facets too
tinyplot(weight ~ Time | Diet, facet = "by", data = ChickWeight, type = "summary")
# Custom/complex function example
tinyplot(
weight ~ Time | Diet, facet = "by", data = ChickWeight,
type = type_summary(function(y) quantile(y, probs = 0.9)/max(y))
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.