Creating a timeline in R

So, my intent is to show the timeline of matching healthcare technologies with their duration as a rectangle or geom tile, the width of which represents the duration over a given time interval on the x-axis and manufacturer on the y-axis.

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

I am using packages ggplot2

and timeline

. Following the example found on the Internet, I've edited your information, only to have the column headers: Device

, Manufacturer

, StartDate

, EndDate

, and to ensure that NULL is not. Thus, I added an artificial end date for many technologies that are still licensed.

By repeating the 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 building data, all geometries are superimposed within the group. I need help to split, fitting text to geoms.

+3


source to share


3 answers


Using the vistime package and provided device.data

:

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

      



enter image description here

+3


source


Well, you are grouping by manufacturer and different devices from the same manufacturer have overlapping dates, so of course the rectangles representing the device's manufacturing time overlap, and the labels too, since they are centered in (overlapping) rectangles:

enter image description here

What can you do is

  • reduce the size of the labels until they no longer overlap (using timeline(... , text.size = 1)

    )

    enter image description here

  • or suppress overlapping labels (using timeline(... , text.color = "transparent")

    )

    enter image description here

    and manually place them where they don't overlap.



Personally, I don't find the overlapping rectangles very readable and would probably choose a different visualization, such as a Gantt chart with one "line" for each product, similar to the following chart:

enter image description here

Here the colors will represent the manufacturer, showing which devices were made by the same company and because the devices do not overlap the lifespan of their product are clearly visible.

Here are some answers that explain how to create Gantt charts in R.

+1


source


You can also use timevis to create interactive graphs, although it is a bit painful to create groups.

Unidentified graphs can be generated as follows (using your data):

library(timevis)
colnames(device.data) <- c("content", "group", "start", "end")
timevis(device.data)

      

enter image description here

0


source







All Articles