geom_segment_c supports coloring segment with continuous colors
geom_segment_c(
mapping = NULL,
data = NULL,
position = "identity",
lineend = "butt",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
arrow = NULL,
arrow.fill = NULL,
...
)add segment layer
set.seed(2019-06-28)
d = data.frame(x = rnorm(10),
xend = rnorm(10),
y = rnorm(10),
yend = rnorm(10),
v1 = rnorm(10),
v2 = rnorm(10))
library(ggplot2)
ggplot(d) + geom_segment_c(aes(x = x, xend = xend, y=y, yend =yend, col0 = v1, col1 = v2)) +
scale_color_viridis_c(name = "continuous colored lines") +
theme_minimal() + theme(legend.position=c(.2, .85)) + xlab(NULL) + ylab(NULL)
#> Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
#> 3.5.0.
#> ℹ Please use the `legend.position.inside` argument of `theme()` instead.
#> Warning: Computation failed in `stat_segment_c()`.
#> Caused by error in `if (quote) ...`:
#> ! argument is not interpretable as logical