Interactive visuals can overcome the dilemma of not want to confuse your data visuals with too much complexity, but also wanting to allow your audience the option of exploring the details.
In R you could use the dygraphs package to create interactive charts. For instance, below I give an example for zooming into a data range and user controlled smoothing of a time-series.
We will get some recent data on wave heights from Queensland (my home state) government. First we load the data directly from the web and process it to correctly label dates and times, then just select the Signficant wave height variable at Tweed Heads.
waves <-read.csv(url("http://www.ehp.qld.gov.au/data-sets/waves/wave-7dayopdata.csv?timestamp=2017-07-05EST21-06-50"), skip = 1)
waves$time <- as.POSIXct(strptime(as.character(waves$DateTime), format = "%Y-%m-%dT%H:%M:%S"))
waves2 <- subset(waves, (Hsig > 0) & (Site == "Tweed Heads"))[,c("time", "Hsig")]
waves_xts <- xts::xts(waves2$Hsig, order.by = waves2$time)
Dates are a bit of a hassle in R, so the second line of codes deals with transforming the dates as provided in the data into dates that are recognised by R.
We then simply subset for times with data Hsig >0
and Tweeds Heads (which is the location of the Quicksilver pro surfing contest!).
Now have our data, we can look at it using the dygraphs package. We will do two things: add a date range selector and also add a ‘roll’ which will smooth over a certain period of our choosing:
library(dygraphs)
dygraph(waves_xts, main = "Significant wave height - Tweed Heads") %>%
dyRoller(rollPeriod = 50) %>%
dyRangeSelector()
Pretty simple. Play around with changing the rollPeriod
number either in the code or on the chart (there is a small box on the lower left hand corner). You can also zoom in to a particular date range.
This means you could show the fine detail (roll period = 1) but zoom into a single day or hour, or show the overall trend (roll period > 20) and zoom out to several days.
Designed by Chris Brown. Source on Github