colorpath | R Documentation |
lines with alternating color "just for the effect".
StatColorPath
geom_colorpath(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
cols = c("black", "white"),
n_seg = 20,
n = 100,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
cols |
vector of alternating colors |
n_seg |
number of segments along line, according to taste |
n |
number of points at which interpolation takes place increase if line takes sharp turns |
... |
Other arguments passed on to |
An object of class StatColorPath
(inherits from Stat
, ggproto
, gg
) of length 3.
Stackoverflow thread https://stackoverflow.com/a/70759994/7941188 Thanks to user Henrik for help to create segments
air_df <- data.frame(x = 1: length(AirPassengers), y = c(AirPassengers))
ggplot(air_df, aes(x, y)) +
geom_colorpath(cols = c("red", "blue", "green"))
dat <- data.frame(x = seq(2,10, 2), y = seq(4,20, 4))
p1 <- ggplot(dat, aes(x = x, y = y)) +
geom_colorpath()
p2 <- ggplot(dat, aes(x, y)) +
geom_colorpath(cols = c("red", "blue"))
p3 <- ggplot(dat, aes(x, y)) +
geom_colorpath(cols = c("red", "blue", "green"))
p4 <- ggplot(dat, aes(x, y)) +
geom_colorpath(cols = c("red", "blue", "green", "white"))
patchwork::wrap_plots(mget(ls(pattern = "p[1-9]")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.