Learn R Programming

decompositionLE (version 1.0.0)

plot_age: Title plot_age

Description

S3 method for plot() that visualizes age-related decomposition breakdowns from a data frame. It pivots columns from decomp_age() output into a long format and creates a formatted bar plot.

Usage

plot_age(x, method, plot_type, line = FALSE)

Value

A ggplot object showing disease breakdown values

Arguments

x

A data frame containing unmodified decomp_age() output.

method

Method used for age decomposition. Same as method argument in decomp_age()

plot_type

Plot either total contribution in years or segmented effect contribution. Options: "total", "segment_dodge".

line

Logical for additional line geom showing total effect if 'segment_dodge' plot_type is selected. FALSE by default. Not available for 'chandrasekaran1' and 'chandrasekaran2' methods.

Details

Plot age decomposition breakdown

Examples

Run this code
age_output <- decomp_age(us_females,
  method = "arriaga3", age_col = "Age", e1 = "e1x",
  e2 = "e2x", l1 = "l1x", l2 = "l2x"
)

plot_age(age_output, method = "arriaga3", plot_type = "segment_dodge")
plot_age(age_output, method = "arriaga3", plot_type = "segment_dodge", line = TRUE)
plot_age(age_output, method = "arriaga3", plot_type = "total", line = TRUE)

Run the code above in your browser using DataLab