| type_lines | R Documentation |
Type function for plotting lines.
type_lines(
type = "l",
dodge = 0,
fixed.dodge = FALSE,
xlevels = NULL,
xord = NULL
)
type |
1-character string giving the type of plot desired. The
following values are possible, for details, see |
dodge |
Adjustment parameter for dodging overlapping points or ranges in grouped plots along the x-axis (or y-axis for flipped plots). Either:
Default value is 0 (no dodging). While we do not check, it is strongly recommended that dodging only be used in cases where the x-axis comprises a limited number of discrete breaks. |
fixed.dodge |
Logical. If |
xlevels, xord |
arguments controlling the order of the (categorical)
Note that |
Like the other plot types, type_lines() places categorical (factor or
character) data according to the factor levels. Character variables are
coerced with factor() and so end up in alphabetical order. To order the
categories by their appearance in the data instead, use
xord = "asis", or set the levels explicitly, e.g.
factor(x, levels = unique(x)).
Note that the lines themselves are always drawn in the order that the rows
arrive in, exactly as base lines() does. Categories whose level order
differs from their row order will therefore produce a zig-zag, just as an
unsorted numeric x-variable would.
# "l" type convenience character string
tinyplot(circumference ~ age | Tree, data = Orange, type = "l")
# Use `type_lines()` to pass extra arguments for customization
tinyplot(circumference ~ age | Tree, data = Orange, type = type_lines(type = "s"))
# Direct legend labels are a good option for grouped lined plots (assuming
# there aren't too many groups and the data are sorted along the x-axis)
tinyplot(
circumference ~ age | Tree, data = Orange, type = "l",
legend = "direct"
)
# Fancier version(s) that use a theme and repel overlapping labels
Orange2 = transform(Orange, Tree = paste("Tree", Tree))
tinyplot(
circumference ~ age | Tree, data = Orange2, type = "l",
legend = list("direct", repel = TRUE), # auto repel
theme = "socviz"
)
tinyplot(
circumference ~ age | Tree, data = Orange2, type = "l",
legend = list("direct", nudge_y = c("Tree 1" = 3, "Tree 3" = -5)), # manual
theme = "socviz"
)
# A continuous `by` variable is also supported (as of tinyplot v0.8.0).
# This is particularly useful for trajectories, where a third variable (often
# time) orders the path.
time = seq(0, 8*pi, length.out = 600)
spiral = data.frame(time = time, x = time * cos(time), y = time * sin(time))
tinyplot(
y ~ x | time, data = spiral,
type = "l",
lwd = 2, asp = 1, # optional args
theme = "clean"
)
# The canonical time-path example: the x-z projection of a Lorenz attractor.
step = function(p, i) {
p + 0.005 * c(
10 * (p[2] - p[1]),
p[1] * (28 - p[3]) - p[2],
p[1] * p[2] - 8/3 * p[3]
)
}
lz = do.call(rbind, Reduce(step, 1:6000, c(1, 1, 1), accumulate = TRUE))
lorenz = data.frame(time = seq_len(nrow(lz)) * 0.005, x = lz[, 1], z = lz[, 3])
tinyplot(z ~ x | time, data = lorenz, type = "l", theme = "clean")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.