View source: R/aec_age_sex_plot.R
aec_age_sex_plot | R Documentation |
Each collection is plotted by age and sex. This function provides a quick way of doing so. Although the function takes a single argument (a data frame containing rates by age and sex, by financial year), it relies on the presence of the following variables to that data frame, which must be precisely named:
age_group_new
A variable giving the age group generated by mandatory_age_group
rate
The rate per 100,000 population
sex
Sex variable, to allow side-by-side bars
fyear6
Financial year
aec_age_sex_plot(x, collection = NULL)
x |
A dataframe as described above. |
collection |
An optional parameter. Specify "cdi" for CDI age and sex structure, otherwise omit. |
A ggplot object
## Not run:
# This isn't pretty but does show how the plot is expected to work.
dat <- structure(list(fyear6 = c(201011L, 201011L, 201011L, 201011L,
201011L, 201011L, 201011L, 201011L, 201011L, 201011L, 201011L,
201011L, 201011L, 201011L, 201516L, 201516L, 201516L, 201516L,
201516L, 201516L, 201516L, 201516L, 201516L, 201516L, 201516L,
201516L, 201516L, 201516L),
age_group_new = c("<1", "1-14", "15-44", "45-64", "65-74", "75-54", ">=85",
"<1", "1-14", "15-44", "45-64", "65-74", "75-54", ">=85",
"<1", "1-14", "15-44", "45-64", "65-74", "75-54", ">=85",
"<1", "1-14", "15-44", "45-64", "65-74", "75-54", ">=85"),
sex = c("Female", "Female", "Female", "Female", "Female", "Female", "Female",
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Female",
"Female", "Female", "Female", "Female", "Female", "Female",
"Male", "Male", "Male", "Male", "Male", "Male", "Male"),
rate = c(0.633245773, 0.885480457, 0.064219518, 0.287795718, 0.804223429,
0.679864585, 0.358524629, 0.08131503, 0.092019692, 0.594467264,
0.487193358, 0.870376164, 0.32395407, 0.466408567, 0.396977702,
0.130634269, 0.228873901, 0.408729264, 0.526498187, 0.787985839,
0.420864088, 0.33889444, 0.592512904, 0.794665159, 0.376888279,
0.189044191, 0.574355996, 0.500617646)),
.Names = c("fyear6", "age_group_new", "sex", "rate"), class = "data.frame",
row.names = c(NA, -28L))
p <- aec_age_sex_plot(dat)
p
dat <- dat[dat$age_group_new != "<1", ]
p <- aec_age_sex_plot(dat, "cdi")
p
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.