我在R中使用 highcharter 库创建了水印图。 我想将另一个变量(或使用任何现有变量调整值)添加到此图中作为时间轴(如图所示)。 此变量的值表也是时间序列数据帧,但值为“0”和“1” 其中“0”表示没有洪水,“1”表示洪水。 所以我想将(仅值“1”)显示为洪水持续时间作为时间线。
library(ggplot2)
library(dplyr)
library(highcharter)
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
在数据文件夹中,Flood.csv包含我想要添加为新变量的数据