i have dataset looks
"year","a","b" 2001,100,177 2002,154,419 2003,334,190 2012,301,90 .. , lot more rows.
"year" columns range 2001 2013. have dataset loaded in data.table "dt"
i want plot graph year on x axis, , line graphs , b on y axis.
in other words, have combine these 2 graphs in one.
dt %>% ggvis(~year, ~a) %>% layer_lines() dt %>% ggvis(~year, ~b) %>% layer_lines() i know way ggplot2 couldn't find way ggvis. shall great if in shiny. highly appreciated.
you can way:
library(ggvis) dt %>% ggvis(x= ~year) %>% layer_lines(y= ~a, stroke:='blue') %>% layer_lines(y= ~b, stroke:='orange') i assume need different colors each line able distinguish groups added stroke argument.
output:

it better if melt data.frame first , plot stroke argument return legend well. this:
library(reshape2) dt2 <- melt(dt, 'year', c('a','b')) dt2 %>% ggvis(~year, ~value, stroke=~variable) %>% layer_lines() 
Comments
Post a Comment