3 minutes
Timeline in R
The following script creates a nice timeline graph in R; it’s contained on the library:timeline – see Reference
citation("timeline")
To cite package ‘timeline’ in publications use:
Jason Bryer (2013). timeline: Timelines for a Grammar of Graphics. R package version 0.9.
http://CRAN.R-project.org/package=timeline
A BibTeX entry for LaTeX users is
@Manual{,
title = {timeline: Timelines for a Grammar of Graphics},
author = {Jason Bryer},
year = {2013},
note = {R package version 0.9},
url = {http://CRAN.R-project.org/package=timeline},
}
As noticed, this function is dependant on the Grammar of Graphics library: ggplot
Data (1st group)
Firstly the source data needs to be stored in the following order : name,domain,initial date,end date,group.
name | domain | initial date | end date | group |
---|---|---|---|---|
4.1 | Warty Warthog | 2004-10-20 | 2006-04-30 | 2.6.8 |
5.04 | Hoary Hedgehog | 2005-04-08 | 2006-10-31 | 2.6.10 |
5.1 | Breezy Badger | 2005-10-13 | 2007-04-13 | 2.6.12 |
6.06 LTS | Dapper Drake | 2006-06-01 | 2009-07-14 | 2.6.15 |
6.06 LTS ext | Dapper Drake | 2009-07-15 | 2011-06-01 | 2.6.15 |
6.1 | Edgy Eft | 2006-10-26 | 2008-04-25 | 2.6.17 |
7.04 | Feisty Fawn | 2007-04-19 | 2008-10-19 | 2.6.20 |
7.1 | Gutsy Gibbon | 2007-10-18 | 2009-04-18 | 2.6.22 |
8.04 LTS | Hardy Heron | 2008-04-24 | 2011-05-12 | 2.6.24 |
8.04 LTS ext | Hardy Heron | 2011-05-13 | 2013-05-09 | 2.6.24 |
8.1 | Intrepid Ibex | 2008-10-30 | 2010-04-30 | 2.6.27 |
9.04 | Jaunty Jackalope | 2009-04-23 | 2010-10-23 | 2.6.28 |
9.1 | Karmic Koala | 2009-10-29 | 2011-04-30 | 2.6.31 |
10.04 LTS | Lucid Lynx | 2010-04-29 | 2013-05-09 | 2.6.32 |
10.04 LTS | Lucid Lynx | 2013-05-10 | 2015-04-30 | 2.6.32 |
10.1 | Maverick Meerkat | 2010-10-10 | 2012-04-10 | 2.6.35 |
11.04 | Natty Narwhal | 2011-04-28 | 2012-10-28 | 2.6.38 |
11.1 | Oneiric Ocelot | 2011-10-13 | 2013-05-09 | 3.0.0 |
12.04 LTS | Precise Pangolin | 2012-04-26 | 2017-04-26 | 3.2.0 |
12.1 | Quantal Quetzal | 2012-10-18 | 2014-05-16 | 3.5.0 |
13.04 | Raring Ringtail | 2013-04-25 | 2014-01-27 | 3.8-0 |
13.1 | Saucy Salamander | 2013-10-17 | 2014-07-17 | 3.11.0 |
14.04 LTS | Trusty Tahr | 2014-04-17 | 2019-04-17 | 3.13⁄3.16 |
14.1 | Utopic Unicorn | 2014-10-23 | 2015-07-17 | 3.16.0 |
15.04 | Vivid Vervet | 2015-04-23 | 2016-09-23 | 3.19.2 |
Data (2nd group)
Secondly the reference dates file is attached [NOTE]1
Name | Release | |
---|---|---|
Windows XP | 2002-06-06 | Win |
Windows Vista | 2007-10-06 | Win |
Windows 7 | 2009-07-06 | Win |
Windows 8 | 2013-10-06 | Win |
OSX Puma | 2002-03-06 | Mac |
OSX Jaguar | 2003-09-06 | Mac |
OSX Leopard | 2007-09-06 | Mac |
OSX Snow Leopard | 2009-09-06 | Mac |
OSX Lion | 2011-06-06 | Mac |
OSX Mountain Lion | 2012-06-06 | Mac |
OSX Mavericks | 2013-09-06 | Mac |
OSX Yosemite | 2014-09-06 | Mac |
R
Once the data is loaded into the R-environment, some adjustments need not be made in order to make the file readable by the function.
require(timeline)
DataGroupA <- read.csv("myData/DataGroup1.csv", header=F, stringsAsFactors=FALSE)
names(DataGroupA) <- c('Name','Domain','StartDate','EndDate')
DataGroupA$StartDate <- as.Date(DataGroupA$StartDate)
DataGroupA$EndDate <- as.Date(DataGroupA$EndDate)
DataGroupB <- read.csv("myData/DataGroup2.csv", header=F, stringsAsFactors=FALSE)
names(DataGroupB) <- c('Event','Date','OS')
DataGroupB$Date <- as.Date(DataGroupB$Date)
Finally, the function timeline()
may be called, enclosing both data-frames as arguments.
timeline(DataGroupA,DataGroupB)
However, despite of the fact that the internal parameters can be modified, as typical options, these can be specified directly. Moreover, in the following script the function is embedded into a local function just to make it available at a different stage.
draw <- function() {
timeline(DataGroupA,DataGroupB,
text.size = 4,
text.alpha = 3,
num.label.steps = 10,
event.spots = 10,
event.label.method = 1,
event.text.size = 3.5,
event.label = '',
event.line = FALSE,
event.above = FALSE)
}
Such new function draw()
is called in a predefined sequence to export the image.
png("myFigures/TimeLine.png", width = 1380, height = 880, units = "px", bg = "transparent", res = NA)
draw()
dev.off()
[- Download Data1.csv]
[- Download Data2.csv]
- These might not be the exact dates, please note that this is just an illustrative example of the timeline function. [return]