daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(plotly)
  2. library(dplyr)
  3.  
  4. sec_y <- list(tickfont = list(color = "red"),
  5.               overlaying = "y",
  6.               side = "right",
  7.               title = "Lft")
  8.  
  9.  
  10. pp1 <- fmean1 %>% group_by(grp) %>%  plot_ly() %>%
  11.   add_lines(x = ~hour, y = ~fmgd, name = "FMGD", colour = "blue") %>%
  12.   add_lines(x = ~hour, y = ~lft, name = "Lft", yaxis = "y2", colour = "red") %>%
  13.      layout(title = "Fbay", yaxis2 = sec_y,
  14.             xaxis = list(title="Date"))
  15.  
  16.  
  17.  
  18. pp2 <- prcpf1 %>% plot_ly() %>%
  19.   add_bars(x=~Datetime, y=~precip, name = "prcp")
  20.  
  21.  
  22.  
  23. subplot(pp1, pp2, nrows = 2 , shareX = T)
  24.      
  25. fmean1 <- structure(list(hour = structure(1:11, .Label = c("2018-04-15
  26. 18:00:00",  "2018-04-15 19:00:00", "2018-04-15 20:00:00", "2018-04-15 21:00:00",
  27. "2018-04-15 22:00:00", "2018-04-15 23:00:00", "2018-04-16 00:00:00",
  28. "2018-04-16 01:00:00", "2018-04-16 02:00:00", "2018-04-16 03:00:00",
  29. "2018-04-16 04:00:00"), class = "factor"), fmgd = c(249.67262,
  30. 278.45789, 349.241726666667, 351.883898333333, 369.18035, 406.85811,
  31. 406.233883333333, 393.751951666667, 390.004548333333, 403.980246666667,
  32. 449.06727), lft = c(84.7313333333333, 85.1555, 85.8243333333333,
  33. 87.7796666666667, 88.8493333333333, 88.1606666666667, 87.1883333333333,
  34. 86.2645, 85.9258333333333, 86.3718333333333, 86.4433333333333
  35. ), grp = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)),
  36. row.names = 91:101, class = "data.frame")
  37.      
  38. prcpf1 <- structure(list(Datetime = structure(c(1523815200, 1523818800,
  39. 1523822400, 1523826000, 1523829600, 1523833200, 1523836800, 1523840400,
  40. 1523844000, 1523847600, 1523851200), class = c("POSIXct", "POSIXt"
  41. ), tzone = "UTC"), precip = c(0.11, 0.09, 0.06, 0.09, 0.03, 0.04,
  42. 0.02, 0.14, 0.07, 0.15, 0.26)), row.names = c(NA, -11L), class = c("tbl_df",
  43. "tbl", "data.frame"))
  44.      
  45. ## Creating axis layouts, explicitly for all y axes
  46. L_Axis <- list(tickfont = list(color = "red"), overlaying = "y",
  47.                side = "right", title = "Lft")
  48.  
  49. F_Axis <- list(side = "left", title = "fmgd")
  50.  
  51. P_Axis <- list(side = "left", title = "prcp")
  52.  
  53.  
  54. pp1 <- fmean1 %>% group_by(grp) %>%  plot_ly() %>%
  55.   add_lines(x = ~hour, y = ~fmgd, name = "FMGD", colour = "blue") %>%
  56.   add_lines(x = ~hour, y = ~lft, name = "Lft", yaxis = "y2", colour = "red") %>%
  57.   layout( yaxis  = F_Axis, #left axis
  58.           yaxis2 = L_Axis, #right axis
  59.           title = "Fbay", xaxis = list(title="Date"))
  60.  
  61.  
  62.  
  63. pp2 <- prcpf1 %>% plot_ly() %>%
  64.   add_bars(x=~Datetime, y=~precip, name = "prcp", yaxis = "y", colour = "green") %>%
  65.   layout(yaxis = P_Axis) #only y axis, on the left
  66.  
  67.  
  68.  
  69. pp <- subplot(pp1, pp2 , nrows = 2 , titleY = T, shareX = T)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top