I am new to R. I have written this code to generate with highcharter library, This is based on the dataframe that I have for 11 years i.e. 2005 - 2011 (for months April - October)
The following code is for one year. I want to create a loop or something similar to create the chart for every year separately. This code works fine but I have to manually change the date for every year and generate a chart.
Year_2005_rain <- subset(Seven,
time >= as.Date('2005-04-01') &
time <= as.Date('2005-10-31'))
Year_2005_flow<- subset(Seven_flow,
time >= as.Date('2005-04-01') &
time <= as.Date('2005-10-31'))
Year_2005_inflow<- subset(Seven_inflow,
time >= as.Date('2005-04-01') &
time <= as.Date('2005-10-31'))
merge1_05 <- merge(Year_2005_rain,
Year_2005_flow,
Year_2005_inflow, by="time")
names(Year_2005_rain) <- names(Year_2005_flow) <- names(Year_2005_inflow)
merge1_05 <- rbind(Year_2005_rain, Year_2005_flow,Year_2005_inflow)
colnames(merge1_05)[colnames(merge1_05)=="time"] <- "date"
colnames(merge1_05)[colnames(merge1_05)=="Discharge"] <- "value"
merge1_05$date = as.Date(merge1_05$date, format = "%Y/%m/%d")
merge1_05$variable <- c(rep("rain", 214), rep("discharge", 214), rep("inflow", 214))
hc_14<- highchart() %>%
hc_yAxis_multiples(list(title = list(text = "rainfall depth (mm)"), reversed = TRUE),
list(title = list(text = "flow (m3/s)"), opposite = TRUE)) %>%
hc_add_series(data = filter(merge1_05, variable == "rain") %>%
mutate(value = value) %>% .$value, type = "column") %>%
hc_add_series(data = filter(merge1_05, variable == "discharge") %>% .$value,
type = "spline", yAxis = 1) %>%
hc_add_series(data = filter(merge1_05, variable == "inflow") %>% .$value,
type = "spline", yAxis = 1) %>%
hc_xAxis(categories = merge1_05$date, title = list(text = "date"))
hc_14