Description Usage Arguments Value Author(s) Examples
View source: R/age_sex_pyramid.R
Create age-sex pyramid
1 2 3 |
data |
a data.frame |
age.grp.col |
a character defining the age-group column within the data.frame |
sex.col |
a character defining the sex column within the data.frame |
lower.limit |
a numeric defining the lower limit for the x-axis |
upper.limit |
a numeric defining the upper limit for the x-axis |
split.by |
a character defining a column to facet by within the data.frame |
col.pal |
a numeric defining the colour palette to use |
blank.background |
a logical specifying if the figure background should be blank |
an age-sex pyramid
Daniel Gardiner (daniel.gardiner@phe.gov.uk)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # set dummy data
set.seed(5)
data = data.frame(sex = sample(c("Male", "Female", "Unknown"), 200, replace = TRUE),
age = sample(c(NA, 1:100), 200, replace = TRUE),
status = sample(c("Confirmed", "Probable"), 200, replace = TRUE))
data$age.grp = cut(as.numeric(data$age), breaks = c(0, 5, 15, 25, 45, 65, Inf),
include.lowest = TRUE)
# age sex pyramid
age_sex_pyramid(data, age.grp.col = "age.grp", sex.col = "sex", split.by = NULL)
# age sex pyramid with lower/upper limit and colour palette
age_sex_pyramid(data, age.grp.col = "age.grp", sex.col = "sex", split.by = NULL,
lower.limit = -50, upper.limit = 40, col.pal = 4)
# age sex pyramid with facet
age_sex_pyramid(data, age.grp.col = "age.grp", sex.col = "sex", split.by = "status")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.