我的目标是编写一个闪亮的应用程序来直观地比较多个时间序列。所有时间序列都具有相同的 x 值范围。垂直堆叠和同步的 dygraphs 很好地显示了单个时间序列的 y 值,以获得共同的 x 值。
如果所有 dygraphs 只有一个 y 轴(即没有“y2”轴),则此方法有效:
library(shiny)
library(dygraphs)
ui <- fluidPage(
mainPanel(
dygraphOutput("one_axis"),
dygraphOutput("two_axis")
)
)
server <- function(input, output) {
output$one_axis <- renderDygraph({
dygraph(fdeaths, group = "foo")
})
output$two_axis <- renderDygraph({
dygraph(mdeaths, group = "foo")
})
}
shinyApp(ui, server)
在我的用例中,一些 dygraphs 有两个 y 轴:“y”和“y2”。带有双 y 轴的绘图的 x 轴被压扁,以便为“y2”轴和标签腾出空间:
library(shiny)
library(dygraphs)
ui <- fluidPage(
mainPanel(
dygraphOutput("one_axis"),
dygraphOutput("two_axis")
)
)
server <- function(input, output) {
output$one_axis <- renderDygraph({
combined <- cbind(mdeaths, fdeaths)
dygraph(combined, group = "foo") %>%
dySeries("mdeaths", axis = "y") %>%
dySeries("fdeaths", axis = "y2")
})
output$two_axis <- renderDygraph({
dygraph(mdeaths, group = "foo")
})
}
shinyApp(ui, server)
问题:
有没有办法对齐所有 dygraphs 的 x 轴,无论它们是否有一个或两个 y 轴?
我尝试过但没有成功的事情:
- 为单个变量添加两个 y 轴
- 玩 dyOptions(rightGap)
我发现了一个类似的问题,但我不熟悉 javascript。
编辑:错字