Title: | Timeline and Time Duration-Related Tools |
---|---|
Description: | An easy tool for plotting annotated timelines, grouped timelines, and exploratory graphics (boxplot/histogram/density plot/scatter plot/line plot). Filter, summarize date data by duration and convert to calendar units. |
Authors: | Dahee Lee [aut, cre], Dustin Tingley [aut] |
Maintainer: | Dahee Lee <[email protected]> |
License: | GPL-2 |
Version: | 0.1.1 |
Built: | 2024-11-17 03:24:08 UTC |
Source: | https://github.com/daheelee/timelines |
Calculates the duration between two dates, use it as a filter to select rows that satisfy the length criteria. Returns the dataset with additional columns regarding the length of durations in different units.
durCalc(df = NULL, start, end, timeunit = "day", filterlength = NA, filterlonger = TRUE, year = 365.25, month = 30.42)
durCalc(df = NULL, start, end, timeunit = "day", filterlength = NA, filterlonger = TRUE, year = 365.25, month = 30.42)
df |
Data frame containing start and end dates. |
start |
Column in df for start dates or a date to use as start date. |
end |
Column in df for end dates or a date to use as a end date. |
timeunit |
Unit of time to be used in plots. |
filterlength |
A time length to use as filter. |
filterlonger |
If TRUE, the function gives rows with longer durations than specified in filterlength. If FALSE, gives rows with shorter durations. |
year |
Number of days to use as a year. Default is 365.25. |
month |
Number of days to use as a month. Default is 30.42. |
Additional columns returned with the filtered rows are: length of duration in days, in specified time unit, and in calendar units, and how much longer/shorter the durations are compared to filter length in calendar units.
If no filterlength
is provided, then returns all rows with length of duration in days and calendar units.
You can use dates for start
and end
and provide no df
to get the length of duration between the dates in calendar units. See example.
A subset of original data frame with additional columns in specified time units and calendar units.
Dahee Lee
### Filter people who lived longer than 85 years durCalc(life_exp, start = "Birth", end = "Death", timeunit = "years", filterlength = 85) ### How old each person would be as of January 1, 2000 if they were alive durCalc(life_exp, start = "Birth", end = as.Date("2000-1-1"), timeunit = "years") ### Use as unit-converter between two dates durCalc(start = as.Date("2010-12-1"), end = as.Date("2015-4-26"), timeunit = "weeks")
### Filter people who lived longer than 85 years durCalc(life_exp, start = "Birth", end = "Death", timeunit = "years", filterlength = 85) ### How old each person would be as of January 1, 2000 if they were alive durCalc(life_exp, start = "Birth", end = as.Date("2000-1-1"), timeunit = "years") ### Use as unit-converter between two dates durCalc(start = as.Date("2010-12-1"), end = as.Date("2015-4-26"), timeunit = "weeks")
Plots boxplot, histogram, density plot, scatter plot, line plot and prints summary statistics for date duration data.
durPlot(df, start, end, group = NA, timeunit = "days", plot_type = "all", facet = FALSE, facet.nrow = NULL, theme = NULL, other = NULL, fill_color = "black", line_color = "black", groupcolor = TRUE, point_size = 2, alpha = NA, binwidth = 0.5, show_legend = TRUE, title=FALSE, title_boxplot = "Boxplot", title_histogram = "Histogram", title_density = "Density Plot", title_scatter = "Scatter Plot", title_line = "Line Plot")
durPlot(df, start, end, group = NA, timeunit = "days", plot_type = "all", facet = FALSE, facet.nrow = NULL, theme = NULL, other = NULL, fill_color = "black", line_color = "black", groupcolor = TRUE, point_size = 2, alpha = NA, binwidth = 0.5, show_legend = TRUE, title=FALSE, title_boxplot = "Boxplot", title_histogram = "Histogram", title_density = "Density Plot", title_scatter = "Scatter Plot", title_line = "Line Plot")
df |
Data frame containing start dates, end dates and groups. |
start |
Column in df for start dates. |
end |
Column in df for end dates. |
group |
Column in df for groups. Default is NA. |
timeunit |
Unit of time to be used in plots. |
plot_type |
One of |
facet |
If TRUE, wraps plots in group facets |
facet.nrow |
Number of rows for facet wrap |
theme |
Add theme elements if needed. |
other |
Add other elements if needed. |
fill_color |
Fill color |
line_color |
Line color |
groupcolor |
If FALSE, fill_color and line_color used for all groups. Default is TRUE. |
point_size |
Point size for scatterplot |
alpha |
Color transparency [0,1] |
binwidth |
Binwidth for histogram; default 0.5. |
show_legend |
Default is TRUE |
title |
If TRUE, puts main titles for each plot |
title_boxplot |
Title for boxplot title |
title_histogram |
Title for histogram |
title_density |
Title for density plot |
title_scatter |
Title for scatter plot |
title_line |
Title for line plot |
The function also returns summary statistics for the specified date duration.
Dahee Lee
timelineS
, timelineG
, durSummary
, durCalc
durPlot(life_exp, start = "Birth", end = "Death", group = "Country", timeunit = "years", facet = TRUE, binwidth = 3, alpha = 0.7, title = TRUE) durPlot(life_exp, start = "Birth", end = "Death", group = "Country", timeunit = "years",alpha = 0.5, title = TRUE)
durPlot(life_exp, start = "Birth", end = "Death", group = "Country", timeunit = "years", facet = TRUE, binwidth = 3, alpha = 0.7, title = TRUE) durPlot(life_exp, start = "Birth", end = "Death", group = "Country", timeunit = "years",alpha = 0.5, title = TRUE)
Returns summary statistics for date duration data (for each group if group
is provided)
durSummary(df, start, end, group = NA, timeunit = "days")
durSummary(df, start, end, group = NA, timeunit = "days")
df |
Data frame containing start and end dates. |
start |
Column in df for start dates. |
end |
Column in df for end dates. |
group |
Column in df for groups. Default NA. |
timeunit |
Unit of time to be used in plots. |
1 year = 365.25 days, 1 month = 30.42 days, 1 year = 52.14 weeks
Dahee Lee
durSummary(life_exp, start = "Birth", end = "Death", group = "Country", timeunit = "years")
durSummary(life_exp, start = "Birth", end = "Death", group = "Country", timeunit = "years")
Dates of birth and death, gender and phases
dataframe of name(character), country(character), gender(character), phase(character) and dates(date)
Dates of birth and death, country, gender and names
dataframe of name(character), country(character), gender(character), and dates(date)
Events and dates of Michael Jackson's life
dataframe of events(character) and dates(date)
Plots faceted timelines for grouped data.
timelineG(df, start, end, names, phase = NA, group1 = NA, group2 = NA, width = 2, color = "grey", theme = NULL, other = NULL)
timelineG(df, start, end, names, phase = NA, group1 = NA, group2 = NA, width = 2, color = "grey", theme = NULL, other = NULL)
df |
Data frame containing start dates, end dates, groups, phases, and names for each timeline. |
start |
Column in df for start dates. |
end |
Column in df for end dates. |
names |
Column in df for names of each timeline |
phase |
Column in df for phases. |
group1 |
Column in df for groups to be used as the rows of the tabular display. Default is NA. |
group2 |
Column in df for groups to be used as the columns of the tabular display. Default is NA. |
width |
Width of each timeline. Default is 2. |
color |
Color of timelines, only used when |
theme |
Add theme elements if needed. |
other |
Add other elements if needed. |
Dahee Lee
### Plot timelines row-grouped by "Country" timelineG(df = life_country, start = "Start", end = "End", names = "Name", phase = "Phase", group1 = "Country") ### Plot timelines row-grouped by "Country" and column-grouped by "Gender" timelineG(df = life_country, start = "Start", end = "End", names = "Name", phase = "Phase", group1 = "Country", group2 = "Gender") ### Plot timelines, no group timelineG(df = life_country, start = "Start", end = "End", names = "Name",color = "grey")
### Plot timelines row-grouped by "Country" timelineG(df = life_country, start = "Start", end = "End", names = "Name", phase = "Phase", group1 = "Country") ### Plot timelines row-grouped by "Country" and column-grouped by "Gender" timelineG(df = life_country, start = "Start", end = "End", names = "Name", phase = "Phase", group1 = "Country", group2 = "Gender") ### Plot timelines, no group timelineG(df = life_country, start = "Start", end = "End", names = "Name",color = "grey")
Plots a horizontal timeline with event descriptions at corresponding dates.
timelineS(df, main = NA, xlab = NA, buffer.days = 600, line.width = 5, line.color = "gray44", scale = "year", scale.format = "%Y", scale.font = 2, scale.orient = 1, scale.above = FALSE, scale.cex = 1, scale.tickwidth = 2, labels = paste(df[[1]], df[[2]]), label.direction = "downup", label.length = c(0.5,0.5,0.8,0.8), label.position = c(1,3), label.color = "gray44", label.cex = 0.8, label.font = 1, label.angle = 0, pch = 20, point.cex = 1, point.color = "gray44")
timelineS(df, main = NA, xlab = NA, buffer.days = 600, line.width = 5, line.color = "gray44", scale = "year", scale.format = "%Y", scale.font = 2, scale.orient = 1, scale.above = FALSE, scale.cex = 1, scale.tickwidth = 2, labels = paste(df[[1]], df[[2]]), label.direction = "downup", label.length = c(0.5,0.5,0.8,0.8), label.position = c(1,3), label.color = "gray44", label.cex = 0.8, label.font = 1, label.angle = 0, pch = 20, point.cex = 1, point.color = "gray44")
df |
Data frame for events and dates. First column for event names and second column for dates in |
main |
Title of the plot. |
xlab |
X axis label. |
buffer.days |
Additional days to add before and after the event dates on the timeline. Default is 600 days. |
line.width |
Timeline width; default 5 |
line.color |
Timeline color. |
scale |
Scale on timeline. One of |
scale.format |
Scale format; default |
scale.font |
Integer specifying font of scale. Default is 2. (1:plain, 2:bold, 3:italic, 4:bold italic, 5:symbol). |
scale.orient |
Orientation of scale; default 1(upright) |
scale.above |
If |
scale.cex |
Scale font size relative to cex. |
scale.tickwidth |
Width of scale tick; default 2. |
labels |
Event labels. Events and corresponding dates as default. |
label.direction |
Direction of labels from timeline. |
label.length |
Distance of event label from the timeline. Could be a single value or a vector of lengths. Default is c(0.5, 0.5, 0.8, 0.8). See details. |
label.position |
Integer specifying label positions; default c(1,3). See details. |
label.color |
Label color(s). |
label.cex |
Font size(s) of event labels; default 0.8. |
label.font |
Integer specifying label font; default 1. |
label.angle |
Angle of text in the label. |
pch |
End point symbol(s). |
point.cex |
End points size(s). |
point.color |
End points color(s). |
label.direction
indicates the direction of event labels from timeline. "downup"
and "updown"
plots
alternating labels; "up"
puts all the labels above and "down"
below the timeline.
label.length
could be a single number or a numeric vector. For label directions "downup"
and "updown"
, use between 0 and 0.9, and for
"up"
and "down"
, use between 0 and 1.6.
For example, label.length = 0.5
produces all the labels at equal lengths, and label.length = c(0.5,0.5,0.8,0.8)
repeats the sequence of lengths.
The positions for label.position
are 1: below 2: left 3: above 4: right.
Dahee Lee
axis.Date
, timelineG
, durCalc
, durPlot
### Default down-up labels timelineS(mj_life, main = "Life of Michael Jackson") ### Labels above timeline and other change in aesthetics timelineS(mj_life, main = "Life of Michael Jackson", label.direction = "up", label.length = c(0.2,0.8,0.4,1.2), label.position = 3, line.color = "blue", label.color = "blue", point.color = "blue", pch = "-")
### Default down-up labels timelineS(mj_life, main = "Life of Michael Jackson") ### Labels above timeline and other change in aesthetics timelineS(mj_life, main = "Life of Michael Jackson", label.direction = "up", label.length = c(0.2,0.8,0.4,1.2), label.position = 3, line.color = "blue", label.color = "blue", point.color = "blue", pch = "-")