fig_density: Plot a density of a score

View source: R/fig_density.R

fig_densityR Documentation

Plot a density of a score

Description

Plot a density of a score

Usage

fig_density(
  df,
  score,
  var_color = NULL,
  var_facet = NULL,
  cutoffs = NULL,
  x_lab = "Score",
  pal = "Paired",
  adjust = 2,
  size = 1.5
)

Arguments

df

a data frame where each row is an individual, containing at least a score column (between 0 and 100)

score

a string (length 1) of the column name for the score variable to print the distribution of

var_color

a string (length 1) of the column name for the variable to set color of density lines by. Default is NULL.

var_facet

a string (length 1) of the column name for the variable to create a ggplot2::facet_grid() with. Default is NULL.

cutoffs

a numeric vector of the cut-offs for the score categorization. Default is NULL.

x_lab

a string (length 1) of x-axis label. Default is "Score".

pal

a string specifying either a manual color to use for the color aesthetic, a character vector explictly specifying the colors to use for the color scale, or as the name of a palette to pass to RColorBrewer::brewer.pal() with the name of the color palette to use for the color scale. Default is "Paired"

adjust

a numeric value to pass to adjust argument of ggplot2::geom_density(). Default is 2.

size

a numeric value to pass to size argument of ggplot2::geom_density(). Default is 1.5.

Details

Plots a histogram of a score that ranges between 0 and 100, with the fill determined by some set categorization of the score. This is the function used to plot the distributions of disability scores resulting from the WHO Model Disability Survey.

Value

A density figure

See Also

Other figure functions: fig_LID(), fig_dist(), fig_poppyramid()

Examples

fig_density(df_adults, score = "disability_score", cutoffs = c(19.1, 34.4, 49.6), 
x_lab = "Disability score")
fig_density(df_adults, score = "disability_score", var_color = "sex", 
cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score")
fig_density(df_adults, score = "disability_score", var_color = "sex", 
var_facet = "age_cat",  cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score")

lindsayevanslee/whomds documentation built on Sept. 9, 2023, 10:54 p.m.