Type: | Package |
Title: | Plot Lexis Diagrams for Demographic Purposes |
Version: | 0.4.0 |
Maintainer: | Philipp Ottolinger <philipp@ottolinger.de> |
Description: | Plots empty Lexis grids, adds lifelines and highlights certain areas of the grid, like cohorts and age groups. |
Imports: | ggplot2, dplyr, tidyr |
Suggests: | knitr, HMDHFDplus |
Depends: | R (≥ 2.10) |
Encoding: | UTF-8 |
LazyData: | true |
License: | GPL-2 |
URL: | https://github.com/ottlngr/LexisPlotR |
RoxygenNote: | 6.1.1 |
NeedsCompilation: | no |
Packaged: | 2020-01-12 13:10:25 UTC; philipp |
Author: | Philipp Ottolinger [cre, aut], Marieke Smilde-Becker [ctb] |
Repository: | CRAN |
Date/Publication: | 2020-01-12 13:30:03 UTC |
Deprecated. Emphasize a certain age in Lexis grid
Description
Add a coloured rectangle to an existing Lexis grid to highlight a certain age in that Lexis grid.
Usage
lexis.age(lg, age, fill = lpr_colours()[2], alpha = 0.7, d = 1)
Arguments
lg |
an existing object originally created with |
age |
numeric, set the age to highlight. |
fill |
character, set colour to fill the rectangle. Default is |
alpha |
numeric, set alpha, the level of transparency for |
d |
numeric, set the size of the age groups. Default is 1. |
Details
Takes an existing Lexis grid and adds a coloured rectangle that highlights all triangles belonging to a certain age.
Value
A ggplot2 object.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lexis <- lexis.grid2(year.start = 1900, year.end = 1905, age.start = 0, age.end = 5)
lexis <- lexis.age(lg = lexis, age = 3)
## End(Not run)
Deprecated. Emphasize a certain cohort in a Lexis grid
Description
Takes an existing Lexis grid and adds a coloured rectangle to highlight a certain cohort.
Usage
lexis.cohort(lg, cohort, fill = lpr_colours()[4], alpha = 0.7, d = 1)
Arguments
lg |
an existing object originally created with |
cohort |
numeric, set the cohort to highlight. |
fill |
character, set the colour of the rectangle. Default is |
alpha |
numeric, set the level of transparency of the rectangle. Default is |
d |
numeric, set the size of the age groups. Default is 1. |
Details
Takes an existing Lexis grid and adds a coloured rectangle to the plot. The rectangle will highlight a certain cohort in the Lexis grid.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lg <- lexis.grid(year.start = 1900, year.end = 1905, age.start = 0, age.end = 5)
lexis.cohort(lg = lg, cohort = 1901)
## End(Not run)
Deprecated. Plot a Lexis grid
Description
lexis.grid() plots the basic Lexis grid.
Usage
lexis.grid(year.start, year.end, age.start, age.end, lwd = 0.3,
force.equal = T)
Arguments
year.start |
integer, set the year the Lexis Diagram starts with. |
year.end |
integer, set the year the Lexis Diagram ends with. |
age.start |
integer, set the age the Lexis Diagram starts with. |
age.end |
integer, set the age the Lexis Diagram ends with. |
lwd |
numeric, set the linewidth of the grid. |
force.equal |
logical, by default |
Details
The function determines the aspect ratio of the x- and y-axis to enforce
isosceles triangles. The aspect ratio will not be effected by defining
width
and height
in pdf()
or other graphic devices.
Because the returned object is a ggplot2 graph, the overall appearence of
the graph can be edited by adding themes()
to the plot.
Value
The functions returns a ggplot2-plot.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lexis.grid(year.start = 1900, year.end = 1905, age.start = 0, age.end = 5)
## End(Not run)
Deprecated. Plot a Lexis grid
Description
lexis.grid() plots the basic Lexis grid.
Usage
lexis.grid2(year.start, year.end, age.start, age.end, lwd = 0.3,
force.equal = T, d = 1)
Arguments
year.start |
integer, set the year the Lexis Diagram starts with. |
year.end |
integer, set the year the Lexis Diagram ends with. |
age.start |
integer, set the age the Lexis Diagram starts with. |
age.end |
integer, set the age the Lexis Diagram ends with. |
lwd |
numeric, set the linewidth of the grid. |
force.equal |
logical, by default |
d |
numeric, set the size of the age groups. Default is 1. |
Details
The function determines the aspect ratio of the x- and y-axis to enforce
isosceles triangles. The aspect ratio will not be effected by defining
width
and height
in pdf()
or other graphic devices.
Because the returned object is a ggplot2 graph, the overall appearence of
the graph can be edited by adding themes()
to the plot.
Value
The functions returns a ggplot2-plot.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lexis.grid(year.start = 1900, year.end = 1905, age.start = 0, age.end = 5)
## End(Not run)
Deprecated. Fill Lexis triangles by HMD data
Description
The function opens an existing Lexis grid and fill the triangles according to data from the Human Mortality Database.
Usage
lexis.hmd(lg, hmd.data, column)
Arguments
lg |
an existing object originally created with |
hmd.data |
a data.frame created with |
column |
character, the name of the column of |
Details
The function creates a subset of hmd.data
that fits in the dimensions of the existing Lexis grid.
The triangles will be filled according to the data in column
.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lg <- lexis.grid(year.start = 1980, year.end = 1985, age.start = 0, age.end = 5)
# Load sample data
path <- system.file("extdata", "Deaths_lexis_sample.txt", package = "LexisPlotR")
deaths.triangles <- prepare.hmd(path)
lexis.hmd(lg = lg, hmd.data = deaths.triangles, column = "Total")
### Plot data not explicitly present in HMD data
deaths.triangles$RatioMale <- deaths.triangles$Male / deaths.triangles$Total
lexis.hmd(lg, deaths.triangles, "RatioMale")
## End(Not run)
Deprecated. Plot lifelines into a Lexis grid
Description
Add lifelines to an existing Lexis grid.
Usage
lexis.lifeline(lg, entry, exit = NA, lineends = F,
colour = lpr_colours()[7], alpha = 1, lwd = 0.5)
Arguments
lg |
an existing object originally created with |
entry |
character, set the entry or birth date of an individual in format |
exit |
character, set the exit or death date of an individual in format |
lineends |
logical, if |
colour |
character, set the colour of the lifelines. Default is |
alpha |
numeric, set the transparency of the lifelines. Default is |
lwd |
numeric, set the linewidth of the lifelines. Default is |
Details
Takes an existing Lexis grid and adds lifelines to the grid. Input can be a single dates or dates from a vector.
Value
A ggplot2 object.
Author(s)
Philipp Ottolinger
Examples
## Not run:
lg <- lexis.grid(year.start = 1900, year.end = 1905, age.start = 0, age.end = 5)
lexis.lifeline(lg = lg, entry = "1901-09-23")
lexis.lifeline(lg = lg, entry = "1901-09-23", exit = "1904-03-03")
## End(Not run)
Deprecated. Emphasize a survey range in a Lexis grid Takes an existing Lexis grid and adds a coloured parallelogram to highlight a survey range.
Description
Deprecated. Emphasize a survey range in a Lexis grid Takes an existing Lexis grid and adds a coloured parallelogram to highlight a survey range.
Usage
lexis.survey(lg, from_date, to_date, from_age, to_age,
fill = lpr_colours()[6], alpha = 0.7)
Arguments
lg |
an existing object originally created with |
from_date |
character, set the beginning of the survey in format |
to_date |
character, set the end of the survey in format |
from_age |
numeric, set the starting age of the survey. |
to_age |
numeric, set the ending age of the survey. |
fill |
character, set the colour to fill the parallelogram. Default is |
alpha |
numeric, set the transparency of the fill colour. Default is |
Details
The function can be used to plot the time and age range of a survey. Use from_date
and to_date
to specify the time range the survey took place and from_age
and to_age
to define the considered ages of participants/observations.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lg <- lexis.grid(year.start = 1980, year.end = 1990, age.start = 30, age.end = 40)
lexis.survey(lg, from_date = "1982-09-01", to_date = "1986-03-01", from_age = 32, to_age = 36)
## End(Not run)
Deprecated. Emphasize a certain year in Lexis grid.
Description
Takes an existing Lexis grid and adds a coloured rectangle to highlight a certain age.
Usage
lexis.year(lg, year, fill = lpr_colours()[3], alpha = 0.7, d = 1)
Arguments
lg |
an existing object originally created with |
year |
numeric, set the year to highlight. |
fill |
character, set the colour of the rectangle. Default is |
alpha |
numeric, set the transparency of the rectangle. Default is |
d |
numeric, set the size of the age groups. Default is 1. |
Details
Takes an existing Lexis grid and adds a coloured rectangle to the plot. The rectangle will highlight a certain year in the grid.
Value
A ggplot2 object.
Author(s)
Philipp Ottoliner
Examples
## Not run:
lg <- lexis.grid(year.start = 1900, year.end = 1905, age.start = 0, age.end = 5)
lexis.year(lg = lg, year = 1902)
## End(Not run)
Emphasize a certain age in Lexis grid
Description
Add a coloured rectangle to an existing Lexis grid to highlight a certain age in that Lexis grid.
Usage
lexis_age(lg, age, delta = 1, fill = lexisplotr_colours()[1],
alpha = 0.7)
Arguments
lg |
an existing object originally created with |
age |
numeric, set the age to highlight. |
delta |
numeric, set the size of the age groups. Default is 1. |
fill |
character, set colour to fill the rectangle. |
alpha |
numeric, set alpha, the level of transparency for |
Details
Takes an existing Lexis grid and adds a coloured rectangle that highlights all triangles belonging to a certain age.
Value
A ggplot2 object.
Author(s)
Philipp Ottolinger
Examples
library(LexisPlotR)
lexis <- lexis_grid(year_start = 1900, year_end = 1905, age_start = 0, age_end = 5)
lexis <- lexis_age(lg = lexis, age = 3)
Emphasize a certain cohort in a Lexis grid
Description
Takes an existing Lexis grid and adds a coloured rectangle to highlight a certain cohort.
Usage
lexis_cohort(lg, cohort, delta = 1, fill = lexisplotr_colours()[3],
alpha = 0.7)
Arguments
lg |
an existing object originally created with |
cohort |
numeric, set the cohort to highlight. |
delta |
numeric, set the size of the age groups. Default is 1. |
fill |
character, set the colour of the rectangle. |
alpha |
numeric, set the level of transparency of the rectangle. Default is |
Details
Takes an existing Lexis grid and adds a coloured rectangle to the plot. The rectangle will highlight a certain cohort in the Lexis grid.
Author(s)
Philipp Ottolinger
Examples
library(LexisPlotR)
lg <- lexis_grid(year_start = 1900, year_end = 1905, age_start = 0, age_end = 5)
lexis_cohort(lg = lg, cohort = 1901)
Plot a Lexis grid
Description
lexis_grid() plots the basic Lexis grid.
Usage
lexis_grid(year_start, year_end, age_start, age_end, delta = 1,
lwd = 0.3, force_equal = TRUE)
Arguments
year_start |
integer, set the year the Lexis Diagram starts with. |
year_end |
integer, set the year the Lexis Diagram ends with. |
age_start |
integer, set the age the Lexis Diagram starts with. |
age_end |
integer, set the age the Lexis Diagram ends with. |
delta |
numeric, set the size of the age groups. Default is 1. |
lwd |
numeric, set the linewidth of the grid. |
force_equal |
logical, by default |
Details
The function determines the aspect ratio of the x- and y-axis to enforce
isosceles triangles. The aspect ratio will not be effected by defining
width
and height
in pdf()
or other graphic devices.
Because the returned object is a ggplot2 graph, the overall appearence of
the graph can be edited by adding themes()
to the plot.
Value
A ggplot object.
Author(s)
Philipp Ottolinger
Examples
library(LexisPlotR)
lexis_grid(year_start = 1900, year_end = 1905, age_start = 0, age_end = 5)
Plot lifelines into a Lexis grid
Description
Add lifelines to an existing Lexis grid.
Usage
lexis_lifeline(lg, birth, entry = NA, exit = NA, lineends = FALSE,
colour = lexisplotr_colours()[5], alpha = 1, lwd = 0.5)
Arguments
lg |
an existing object originally created with |
birth |
character, set the birth date of an individual in format |
entry |
character, set the entry of an individual in format |
exit |
character, set the exit or death date of an individual in format |
lineends |
logical, if |
colour |
character, set the colour of the lifelines. |
alpha |
numeric, set the transparency of the lifelines. Default is |
lwd |
numeric, set the linewidth of the lifelines. Default is |
Details
Takes an existing Lexis grid and adds lifelines to the grid. Input can be a single dates or dates from a vector.
Value
A ggplot2 object.
Author(s)
Philipp Ottolinger
Examples
lg <- lexis_grid(year_start = 1900, year_end = 1905, age_start = 0, age_end = 5)
lexis_lifeline(lg = lg, birth = "1901-09-23")
lexis_lifeline(lg = lg, birth = "1901-09-23", entry = "1902-04-01")
lexis_lifeline(lg = lg, birth = "1901-09-23", exit = "1904-10-31")
Plot a polygon inside a Lexis grid Takes an existing Lexis grid and adds a polygon.
Description
Plot a polygon inside a Lexis grid Takes an existing Lexis grid and adds a polygon.
Usage
lexis_polygon(lg, x, y, group = 1, fill = lexisplotr_colours()[4],
alpha = 0.7)
Arguments
lg |
an existing object originally created with |
x |
vector describing the x coordinates of the polygon. Format: YYYY-MM-DD. |
y |
vector describing the y coordinates of the polygon |
group |
vector describing the groups of coordinates. |
fill |
character, fill colour of the polygon. |
alpha |
numeric, transparency of the fill colour. Default: 0.7. |
Details
The function can be used to plot a polygon inside a Lexis grid.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
lg <- lexis_grid(year_start = 1900, year_end = 1905, age_start = 0, age_end = 5)
lexis_polygon(lg, x = c("1901-06-30", "1904-06-30", "1904-06-30", "1901-06-30"), y = c(2,2,4,4))
## End(Not run)
Emphasize a certain year in Lexis grid.
Description
Takes an existing Lexis grid and adds a coloured rectangle to highlight a certain age.
Usage
lexis_year(lg, year, delta = 1, fill = lexisplotr_colours()[2],
alpha = 0.7)
Arguments
lg |
an existing object originally created with |
year |
numeric, set the year to highlight. |
delta |
numeric, set the size of the age groups. Default is 1. |
fill |
character, set the colour of the rectangle. |
alpha |
numeric, set the transparency of the rectangle. Default is |
Details
Takes an existing Lexis grid and adds a coloured rectangle to the plot. The rectangle will highlight a certain year in the grid.
Value
A ggplot2 object.
Author(s)
Philipp Ottoliner
Examples
lg <- lexis_grid(year_start = 1900, year_end = 1905, age_start = 0, age_end = 5)
lexis_year(lg = lg, year = 1902)
Data for 300 random lifelines
Description
This dataset contains 300 random entry dates and 150 exit dates for demonstration purposes.
Usage
lifelines_sample
Format
A data frame with 300 rows and 2 variables:
- entry
entry or birth dates.
- exit
exit or death dates,
NA
if not observed.
Deprecated. Prepare HMD data for lexis.hmd()
Description
prepare.hmd()
prepares the raw 'Deaths by Lexis triangles' HMD data for further use by lexis.hmd
.
Usage
prepare.hmd(file)
Arguments
file |
the name of the 'Deaths by Lexis triangles' file downloaded from the Human Mortality Database. |
Details
This function reads the raw data into R and transforms data to numeric
and Date
.
Furthermore seven columns (upper, x1, x2, x3, y1, y2, y3
) that contain the coordinates of the triangles will be added.
The age group 110+
will be removed from the data.
Author(s)
Philipp Ottolinger
Examples
## Not run:
library(LexisPlotR)
# Load sample data
path <- system.file("extdata", "Deaths_lexis_sample.txt", package = "LexisPlotR")
deaths.triangles <- prepare.hmd(path)
## End(Not run)
Tidy triangular data (Lexis triangles)
Description
Take raw data from a data source (e.g. Human Mortality Database) and make it 'tidy'.
Usage
tidy_triangle_data(triangle_data, source = "HMD")
Arguments
triangle_data |
data.frame, A data.frame containing raw triangle data. |
source |
character, The source of the raw data. Supported sources: HMD. |
Details
When using raw triangular data from HMD or other sources, the data is not well prepared for further use. tidy_triangular_data
does some transformations to prepare the data, mainly for visualization using ggplot2
.
Value
A data.frame.
Author(s)
Philipp Ottolinger
Examples
## Not run:
triangles <- readHMDweb("RUS", "Deaths_lexis", "your@email.com", "your_password")
## End(Not run)