This tutorial demonstrates how to create interactive timelines (or Gantt charts) like the one below using a variety of different libraries, currently including; ggplot2 and googleVis.
2+2
## [1] 4
The datasets that this tutorial considers are structured as follows:
Where the “Start Date” and “End Date” column contain the start and end dates for the events, which must be formatted as YYYY-MM-DD. If your dates are not formatted like this, then refer to the “Date Manipulations Script” provided separartely. The “Timeline Label” and “Timeline Tooltip Info” columns provide information about how the events should be labelled in the timeline and what should be shown in the tooltip, respectively. Finally, the “Event Category” column is used for colour coding events.
Note that this template covers both how to build gantt charts inside of an HTML RMarkdown file and how to functionalise the code so as to conveniently switch between different categories and metrics in a Shiny app.
These can be generated fairly easily:
library(googleVis)
datTL <- data.frame(Position = c(rep("President", 3), rep("Vice", 3), "President"),
Name = c("Washington", "Adams", "Jefferson", "Adams", "Jefferson", "Burr",
"Washington"), start = as.Date(x = c(rep(c("1789-03-29", "1797-02-03",
"1801-02-03"), 2), "1801-02-03")), end = as.Date(x = c(rep(c("1797-02-03",
"1801-02-03", "1809-02-03"), 2), "1809-02-03")))
Timeline <- gvisTimeline(data = datTL, rowlabel = "Name", barlabel = "Position",
start = "start", end = "end", options = list(timeline = "{groupByRowLabel:true}",
backgroundColor = "#ffd", height = 350))
plot(Timeline)
However, currently the only support for Shiny applications is in displaying the timeline (via htmlOutput) - there is not an easily provided mechanism for collecting click events from the timeline.