Creating a Timeline in R

kpars picture kpars · May 30, 2017 · Viewed 15.5k times · Source

So my intention here is to show a timeline of concurrent health technologies, with their duration as a rectangle or tile geom, who's width represents duration over a specified time interval on the x-axis, and by manufacturer along the Y-axis.

I have 16 cases, from 4 different manufacturers over a time from 2001-01-01 to 2016-03-31

I am using the ggplot2 and timeline packages. Following an example found online, I edited my data to have only the column headers: Device, Manufacturer, StartDate, EndDate, as well as making sure there are no NULL cases. As such I added an artificial end date to many of the technologies which are still licensed to date.

Trying again with sample data, we have:

    device.data <- data.frame(
    DeviceName = c("Cypher Sirolimus DES", "Taxus Express 2", "Cypher Select Sirolimus DES",
              "Cypher Select Plus Sirolimus DES", "Taxus Liberte", "Endeavor ABT578",
              "Endeavor Sprint Zotarolimus DES", "Xience V", "Taxus Element Monrail ION",
              "Xience Nano", "Promus Element Plus", "Xience Prime",
             "Endeavor Resolute DES","Endeavor Resolute Integrity DES", "Promus Premier", "Xience Xpedition LL and SV"),
    DeviceManufacturer = c("Cordis Cashel","Boston Scientific","Cordis Cashel",
                     "Cordis Cashel","Boston Scientific","Medtronic Inc",
                     "Medtronic Inc", "Abbott Vascular", "Boston Scientific",
                     "Abbott Vascular","Boston Scientific", "Abbott Vascular",
                     "Medtronic Inc", "Medtronic Inc","Boston Scientific", "Abbott Vascular"),
    start_date = as.Date(c("2002-11-15", "2003-09-09", "2005-10-21", 
                     "2006-10-25","2008-02-05", "2008-02-27",
                     "2009-06-10", "2009-08-21", "2011-08-19",
                     "2011-10-24", "2012-01-30", "2012-04-10",
                     "2012-04-14", "2013-03-07", "2013-09-30", "2014-02-19")),
    end_date = as.Date(c("2007-07-18", "2010-11-10", "2007-07-18",
                   "2013-04-05", "2013-11-01", "2016-03-31",
                   "2016-03-31", "2016-03-31", "2011-09-16",
                   "2016-03-31", "2016-03-31", "2016-03-31",
                   "2016-03-31", "2016-03-31", "2016-03-31", "2016-03-31")),
    stringsAsFactors = FALSE
    )
    #data visualization
    timeline(device.data)

When plotting the data however, all of the geoms are superimposed within a group. I need help spacing out, fitting the text to the geoms.

Answer

shosaco picture shosaco · Jul 1, 2017

Using package vistime and your provided device.data:

library(vistime)
vistime(device.data, events = "DeviceName", groups = "DeviceManufacturer", 
                     start = "start_date", end = "end_date")

enter image description here