Learn R Programming

⚠️There's a newer version (2.1.0) of this package.Take me there.

timevis - Create interactive timeline visualizations in R

timevis lets you create rich and fully interactive timeline visualizations in R. Timelines can be included in Shiny apps and R markdown documents, or viewed from the R console and RStudio Viewer. timevis includes an extensive API to manipulate a timeline after creation, and supports getting data out of the visualization into R. This package is based on the vis.js Timeline module and the htmlwidgets R package.

Demo

Click here to view a live interactive demo of timevis.

Installation

timevis is available through both CRAN and GitHub:

To install the stable CRAN version:

install.packages("timevis")

To install the latest development version from GitHub:

install.packages("devtools")
devtools::install_github("daattali/timevis")

How to use

You can view a minimal timeline without any data by simply running

library(timevis)
timevis()

You can add data to the timeline by supplying a data.frame

data <- data.frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)

timevis(data)

Every item must have a content and a start variable. If the item is a range rather than a single point in time, you can supply an end as well. id is only required if you want to access or manipulate an item. There are more variables that can be used in the data.frame -- they are all documented in the documentation for ?timevis().

The content of an item can even include HTML, which makes it easy to show any kind of data in a timeline, such as the matches of the 2014 World Cup:

If you know some CSS, you can completely customize the look of the timeline:

By default, a timeline will show the current date as a red vertical line and will have zoom in/out buttons. You can supply many customization options to timevis() in order to get it just right (see ?timevis() for details).

Interactivity

The timeline lets the user interact with it seamlessly. You can click on the zoom in/out buttons or drag the timeline left/right in order to move to past/future dates.

If you set the editable = TRUE option, then the user will be able to add new items by double clicking, modify items by dragging, and delete items by selecting them.

In a Shiny app

You can add a timeline to a Shiny app by adding timevisOutput() to the UI and renderTimevis(timevis()) to the server.

There are many functions that allow programmatic manipulation of a timeline. For example, addItem() programmatically adds a new item, centerItem() moves the timeline so that the given item is centered, setWindow() sets the start and end dates of the timeline, and more functions are available.

It is also possible to retrieve data from a timeline in a Shiny app. There are several types of data that are available, such as retriving the IDs of the currently selected items, or getting the data in the timeline (as a dataframe). These data will be available as input variables. For more information, read about the getSelected, getWindow, getData, and getIds parameters of timevis().

You can view examples of many of the features supported by checking out the demo Shiny app. If you want to see how those examples were created, the full code for the examples is inside inst/example.

Copy Link

Version

Install

install.packages('timevis')

Monthly Downloads

1,560

Version

0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Dean Attali

Last Published

July 25th, 2016

Functions in timevis (0.1)

removeItem

Remove an item from a timeline
setItems

Set the items of a timeline
removeCustomTime

Remove a custom time previously added
addItem

Add a single item to a timeline
fitWindow

Adjust the visible window such that it fits all items
centerItem

Move the window such that given item or items are centered
centerTime

Move the window such that the given time is centered
addItems

Add multiple items to a timeline
runExample

Run examples of using timevis in a Shiny app
addCustomTime

Add new vertical bar at a time point that can be dragged by the user
setOptions

Update the configuration options of a timeline
timevis-shiny

Shiny bindings for timevis
setWindow

Set the current visible window
timevis

Create a timeline visualization
setSelection

Select one or multiple items on a timeline