# "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")
Run the code above in your browser using DataLab