我正在使用dygraphs软件包编程R中的Shiny应用程序。R/Shiny dygraphs软件包中突出显示的图例
该应用程序提供了一个交互式图表,该图表使用dyHighlight()
函数突出显示所选系列。但是,由于数据涉及1000列,因此图例显示1000个系列。
这里是仅2列的最小代码例如:
ui <- fluidPage(
# This CSS code should solve the problem, but somehow does not.
# To test, replace CSS in tags$style(...) with this code
#.dygraph-legend { display: none; }
#.dygraph-legend .highlight { display: inline; }
# CSS to highlight selected series in legend.
# Does not solve problem, but is best alternative for now.
tags$style("
.highlight {
border: 2px solid black;
background-color: #B0B0B0;
}
"),
sidebarLayout(
sidebarPanel(),
mainPanel(dygraphOutput("plot"))
)
)
server <- function(input, output) {
set.seed(123)
data <- matrix(rnorm(12), ncol = 2)
data <- ts(data)
# Workaround for what might be a bug
# Reference: https://stackoverflow.com/questions/28305610/use-dygraph-for-r-to-plot-xts-time-series-by-year-only
data <- cbind(as.xts(data[,1]), as.xts(data[,2]))
colnames(data) <- c("Series 1", "Series 2")
#print(data) # Uncomment to view data frame
output$plot <- renderDygraph({
dygraph(data) %>%
# Highlighting series
dyHighlight(data,
highlightCircleSize = 2,
highlightSeriesBackgroundAlpha = .5,
highlightSeriesOpts = list(strokeWidth = 2))
})
}
shinyApp(ui = ui, server = server)
有一种方法来调整R中的图例/闪亮,以便只突出显示系列(而不是所有系列在同一时间点)显示?
低2个地块下面的链接节目究竟应该怎样实现:http://dygraphs.com/gallery/#g/highlighted-series
这已经质疑计算器几次,但尚未答复或不工作(+我不想死灵帖子):
Is there a way to highlight closest series in R dygraphs?
Highlight Closest Series - but only show X/Y of highlighted series?
100 labels in separate div with highlighted series in a box
总之,dyHighlight()
似乎并不具备支持此功能,所以JavaScript和CSS很可能需要一个内置的说法。
搜索互联网使我highlightSeriesOpts
,从以下链接highlightCallback
和unhighlightCallback
: http://dygraphs.com/options.html
但你如何使用R这些选项?
您在与重复的例子,这个问题的尝试将是有益的 –
你应该有一个时间序列对象,你数据不是,请提供相关数据 –
完成,请参阅OP :) –