library(plotly)
library(quantmod)
library(xml2)
library(zoo)
# create daily data for 5 years
z = as.character(seq.POSIXt(as.POSIXct(as.Date("2000-11-30")),
as.POSIXct(as.Date("2005-11-30")), by = "1 day"))
# define a variable L
L = 1824 # L is the nrow of the z data frame, such that z is divisible by 4
z = z[1:L] # subset timeseries data frame so it is divisible by 4
str(z) # object is class 'character' and divisible by 4. proceed.
## chr [1:1824] "2000-11-29 16:00:00" "2000-11-30 16:00:00" ...
# create data frame of 2 group variables to test
dat = data.frame(time = z,
head = rnorm(L, mean = 16, sd = 2),
SWL = rnorm(L, mean = 14, sd = 3))
head(dat) # view the 15 minute data
## time head SWL
## 1 2000-11-29 16:00:00 18.68527 15.78024
## 2 2000-11-30 16:00:00 16.66799 18.09401
## 3 2000-12-01 16:00:00 14.43499 13.25714
## 4 2000-12-02 16:00:00 15.97648 11.86142
## 5 2000-12-03 16:00:00 15.72133 18.52540
## 6 2000-12-04 16:00:00 15.55472 13.48091
ds <- data.frame(Date = as.Date(dat$time), dat$head, dat$SWL)
p <- plot_ly(ds, x = ~Date) %>%
add_lines(y = ~dat.head, name = "head") %>%
add_lines(y = ~dat.SWL, name = "SWL") %>%
layout(
title = "Head and SWL",
xaxis = list(
rangeselector = list(
buttons = list(
list(
count = 3,
label = "3 mo",
step = "month",
stepmode = "backward"),
list(
count = 6,
label = "6 mo",
step = "month",
stepmode = "backward"),
list(
count = 1,
label = "1 yr",
step = "year",
stepmode = "backward"),
list(
count = 1,
label = "YTD",
step = "year",
stepmode = "todate"),
list(step = "all"))),
rangeslider = list(type = "date")),
yaxis = list(title = "elevation above sea level (ft)"))
p
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.