Guest User

Untitled

a guest
Mar 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. library(tidyverse)
  2. library(plotly)
  3. set.seed(2001)
  4.  
  5. ## make 10 random data series
  6. data <- data.frame(
  7. t = rep(1:50, 10),
  8. id = sort(rep(1:10, 50)),
  9. y = rnorm(500)
  10. )
  11.  
  12. ## cumulate the random variates by group
  13. data <- data %>%
  14. group_by(id) %>%
  15. mutate(y2 = cumsum(y))
  16.  
  17. ## plot
  18. plot <- data %>%
  19. plot_ly(x = ~ t, y = ~y2, text = ~id) %>%
  20. add_lines(split = ~id, color = I('gray'), alpha = 0.5) %>%
  21. hide_legend()
  22. plot
Add Comment
Please, Sign In to add comment