Is there a possibility to show/hide the series interactively in a R dygraph?
The idea is to compare many time series and have for example a ticking box where one could select/deselect the series to show or hide any of them.
I could not find such an option in the dygraphs
package. Such ticking legend exist for example in the package leaflet
with addLayersControl()
.
I know the question is about R and 4 years old, but I ran into this same need in JavaScript. I put together an implementation of this for my own JS, thought others might be interested.
In my case, I'm displaying historical data for a device (voltage, current, etc). Part of that involves building a readable title for the graph, such as "Generator 1: Voltage, Current". the
data
array contains all my results, and theproperty
of each dataset is the readable title. When I am looping through to build my main title I do this:When I build my graph, i do:
Now my array of booleans for each dataset is stored as a property of my graph object.
When I build my title, I do:
Now I have an array of links for running my visibility toggles. For my function, i have:
In future I might try to put it in the legend instead, but for now this is lovely. Here's an example of it in action. I haven't copied it over to my live unit yet, so the dataset is just a line, but you get the idea:
https://i.imgur.com/K3mq0oA.png