I have multiple paths with multiple segments. How does one color the Nth segment of each path with the same color?
For example:
require(dplyr)
require(ggvis)
df <- data.frame(x = runif(10,0,10), y = runif(10,0,10),
group=c(rep(5,5),rep(10,5)), colorIdx=rep(c(1:5), 2))
df$group = factor(df$group)
color_fun = colorRampPalette(c("yellow","blue"),5)
myColors = color_fun(5)
df$color = myColors[df$colorIdx]
df %>% group_by(group) %>%
ggvis(~x, ~y, strokeWidth:=~group) %>% layer_paths(stroke :=~color)
The resulting paths are monochromatic - I'd like them to scale from yellow to blue.
Using ggplot2, this can be accomplished with:
require(ggplot2)
ggplot(df, aes(x=x, y=y, group=group, colour=colorIdx, size=group)) + geom_path() +
scale_colour_gradient("", low="#FED863", high="#2A6EBB", limits=c(1,4))