Skip to contents

Creates a scatter plot comparing two indicators or two variables from HMIS data.

Usage

plot_scatter(
  data,
  x,
  y,
  color = "state",
  title = NULL,
  x_label = NULL,
  y_label = NULL,
  add_smooth = TRUE
)

Arguments

data

A wide-format data frame with columns for x and y values, or a result from get_hmis() that will be pivoted.

x

Character. Column name or indicator name for x-axis.

y

Character. Column name or indicator name for y-axis.

color

Column for color grouping. Default "state".

title

Plot title. Default auto-generated.

x_label

X-axis label. Default uses x.

y_label

Y-axis label. Default uses y.

add_smooth

Add a LOESS smoothing line. Default TRUE.

Value

A ggplot object.

Examples

if (FALSE) { # \dontrun{
# Compare two indicators
male <- get_hmis("Number of male live births",
  category = "Total", sector = "Total"
)
female <- get_hmis("Number of female live births",
  category = "Total", sector = "Total"
)
combined <- dplyr::inner_join(
  male |> dplyr::select(state, monyear, male = value),
  female |> dplyr::select(state, monyear, female = value),
  by = c("state", "monyear")
)
plot_scatter(combined, x = "male", y = "female")
} # }