I am plotting a ggvis graph with different colors and linetype by setting stroke and strokeDash parameters. The colors are not showing what I want, for ex: I need "red", "blue" and "green" colors where as the colors shown are " blue", "orange" and "green".(code example and screenshot are below).
I also need to add legend based on the color and linetype. I am unable to add the legend combining both "color type"(stroke) and "line type"(strokeDash).
Below is a sample code I am working.
mydf <- data.frame(xval = c(1:5),USA = c(11:15), Canada = c(21:25), UK = c(31:35))
mydf2 <- tidyr::gather(mydf, 'var', 'val', -xval)
mydf2$mycol <- c(rep("Red",5), rep("Blue",5), rep("Green",5))
mydf2$mydash <- c(rep(5,5), rep(-1,5), rep(10,5))
myggv2 <- mydf2 %>% ggvis(x = ~xval, y = ~val, stroke = ~mycol,
strokeDash := ~mydash) %>% layer_points(size := 100) %>%
add_tooltip(function(d) { paste0("x:", d$xval, "<br>", "y:", d$val) }, "hover") %>% group_by(var) %>%
layer_paths() %>% add_axis("x", title = "qtrs") %>%
add_axis("y", title = "MEV")%>% hide_legend("stroke")
myggv2
Here is the screenshot of the graph.Screenshot
Thanks
:=
to set colors instead of map colors. See the answer here. If I wanted a legend, though, I might mapvar
to stroke and then change the colors usingscale_nominal
. There is currently nostrokeDash
legend available. See here.