Skip to contents

Barplot of ratios of residential population (or other) scores to averages - simpler syntax

Helper - Barplot of ratios of indicators (at a site or all sites overall) to US or State average

helper - Barplot of ratios of residential population percentages (or other scores) to averages (or other references)

Usage

ejam2barplot(
  ejamitout,
  varnames = c(names_d_ratio_to_avg, names_d_subgroups_ratio_to_avg),
  sitenumber = NULL,
  main = "Residential Populations at the Analyzed Locations Compared to US Overall",
  ...
)

plot_barplot_ratios_ez(
  out,
  varnames = c(names_d_ratio_to_avg, names_d_subgroups_ratio_to_avg),
  main = "Residential Populations at the Analyzed Locations Compared to US Overall",
  single_location = FALSE,
  row_index = NULL,
  ...
)

plot_barplot_ratios(
  ratio.to.us.d.overall,
  shortlabels = NULL,
  mycolorsavailable = c("gray", "yellow", "orange", "red"),
  main = "Residential Populations at the Analyzed Locations Compared to US Overall",
  ylab = "Ratio vs. Average",
  caption = "NH = \"non-Hispanic\"\nNHA = \"non-Hispanic alone, aka single race\""
)

Arguments

ejamitout

like from ejamit()

varnames

vector of indicator names that are colnames in out$results_overall or out$results_bysite, like names_d_ratio_to_state_avg or names_d_subgroups_ratio_to_state_avg, but not a mix of US and State ratios.

sitenumber

default is all sites from ejamitout$results_overall, and if an integer, it is the row number to show from ejamitout$results_bysite. Important: note this is the row number which is NOT necessarily the same as the ejamitout$results_bysite$ejam_uniq_id notably if FIPS codes were being analyzed.

main

optional, title for plot, like "Analyzed Locations Compared to US Overall", or if using state ratios, include the word "State" to have it try to infer what the legend should be

...

passed to plot_barplot_ratios()

out

the list of tables that is the output of ejamit() or a related function

single_location

set to TRUE and provide row_index to view one site, set to FALSE to view overall results from out$results_overall

row_index

the number of the row to use from out$results_bysite, if single_location = TRUE.

ratio.to.us.d.overall

named list of a few ratios to plot, but see ejam2barplot() for an easier way to specify which indicator to show.

shortlabels

optional, names to use for plot - should be same length as named list ratio.to.us.d.overall

mycolorsavailable

optional (best to leave as default)

ylab

optional, label for y axis

caption

text for a key defining some terms that are abbreviations

Value

ggplot

ggplot should be returned

Details

Used by and similar to ejam2barplot(), which is an easier way to do this! This function requires you to specify single_location = TRUE when using the row_index param. The ejam2barplot() function just uses a sitenumber parameter.

This function is more flexible than plot_barplot_ratios(), which it relies on, since this lets you specify whether to use overall results from ejamit()$results_overall or just one site from ejamit()$results_bysite

If the parameter called main has the word "State" in it, then the legend will refer to "State Average" instead of "US Average" – You cannot plot both types at the same time, so the ratio.to.us.d.overall parameter should be either just ratios to average in US or just ratios to average in State.

See also

ejam2ratios() ejam2barplot() plot_barplot_ratios_ez() ejam2excel()

Examples


# Check a long list of indicators for any that are elevated

out <- testoutput_ejamit_100pts_1miles

ejam2barplot(out,
  varnames = names_these_ratio_to_avg,
  main = "Envt & Demog Indicators at Selected Sites Compared to State Averages")

ejam2barplot(out,
  varnames = names_these_ratio_to_state_avg,
  main = "Envt & Demog Indicators at Selected Sites Compared to State Averages")

# Residential population percentages only

# vs nationwide avg
ejam2barplot(out)

# vs statewide avg
ejam2barplot(out,
  varnames = c(names_d_ratio_to_state_avg, names_d_subgroups_ratio_to_state_avg),
  main = "Residential Populations at Selected Sites Compared to State Averages")

# Environmental only

ejam2barplot(out,
  varnames = c(names_e_ratio_to_avg, names_e_ratio_to_state_avg),
  main = "Environmental Indicators at Selected Sites Compared to Averages")

 ## select your own ratio-type indicators that are available
 ## -- and you could see the range of available ratio indicators like this:
 if (FALSE) { # \dontrun{
 varinfo(
   grep("ratio",
        names(testoutput_ejamit_10pts_1miles$results_overall),
        value = TRUE),
   info = c("varlist", "shortname")
 )
   } # }

 # helper functions related to ejam2barplot()

  plot_barplot_ratios_ez(
    out,
    varnames = c(names_d_ratio_to_avg , names_d_subgroups_ratio_to_avg)
  )

  # same plot but with function that would need more work to format inputs:
  plot_barplot_ratios(
      unlist(out$results_overall[ ,
      c(..names_d_ratio_to_avg , ..names_d_subgroups_ratio_to_avg) ])
      )