使用相关的 R 包将信息添加到 dygraph 的信息框中

Add info to the info box of a dygraph with the relevant R package

#libraries
library(data.table)
library(dygraphs)
library(xts)

#dummy data
dates <- data.table(dates  = seq.Date(as.Date("2017-03-01"), length = 14, by = "month"),
                    satisfaction = runif(14, min = 0.1, max = 1),
                    answers = runif(14, min = 100, max = 1000),
                    )

#convert to xts
xts_dates <- xts(dates, order.by = as.POSIXct(dates$dates, format = ("%Y-%m-%d")))
dygraph(xts_dates)

我只想绘制 satisfaction 并将 answers 数据添加到右上角的信息框或其他可见的地方

#libraries
library(data.table)
library(dygraphs)
library(xts)

#dummy data
dates <- data.table(dates  = seq.Date(as.Date("2017-03-01"), length = 14, by = "month"),
                    satisfaction = runif(14, min = 0.1, max = 1),
                    answers = runif(14, min = 100, max = 1000)
                    )

#convert to xts
xts_dates <- xts(dates, order.by = as.POSIXct(dates$dates, format = ("%Y-%m-%d")))
xts_dates <- xts_dates[, 2:3]

#create dygraph with double axes
dygraph(xts_dates, main = "Satisfaction") %>%
  dyAxis("y", label = "Satisfaction") %>%
  dyAxis("y2", label = "Number of answers", independentTicks = TRUE) %>%
  dySeries("answers", axis = 'y2')

基本上,我为答案数量添加了一个附加轴。