Each groups distribution of distances
Source:R/plot_distance_cdf_by_group.R
distance_by_group_plot.Rd
SLOW / needs to be optimized. CDF Line Plots of cumulative share of each residential population group, within each distance
Usage
distance_by_group_plot(
results_bybg_people = NULL,
radius_miles =
round(max(results_bybg_people$distance_min_avgperson[!is.infinite(results_bybg_people$distance_min_avgperson)],
na.rm = T), table_rounding_info("distance_min_avgperson")),
subgroups_type = NULL,
demogvarname = NULL,
demoglabel = NULL,
colorlist = colorspace::diverging_hcl(length(demogvarname)),
coloroverall = "black",
returnwhat = "table",
...
)
Arguments
- results_bybg_people
data.table from doaggregate()$results_bybg_people
- radius_miles
miles radius that was max distance analyzed
- subgroups_type
optional, can be set to "nh" or "alone". Specifies types of race ethnicity subgroups to use for demogvarname but only if demogvarname is not specified as a parameter. If neither is specified it tries to use default_subgroups_type if that is a variable set by global.R, since it cannot check the reactive variable input$subgroups_type outside the context of the web app.
- demogvarname
optional way to specify names of columns to use from results_bybg_people, e.g., c("pctlowinc", "pctmin"), or namez$d, or could be a vector of subgroups such as namez$d_subgroups_nh that includes "pctnhba" etc. or namez$d_subgroups_alone that includes "pctba" etc., but if demogvarname is not specified here as a parameter, this info could also be specified by the subgroups_type parameter here. If neither is specified, the function will try to use a default
- demoglabel
friendly text names for labelling graphic, like "Low income residents"
- colorlist
colors like "red" etc. for the residential population groups of interest
- coloroverall
color like "gray" for everyone as a whole
- returnwhat
If returnwhat is "table", invisibly returns a full table of sorted distances of blockgroups, cumulative count of demog groups at that block group's distance. If returnwhat is "plotfilename" then it returns the full path including filename of a .png in a tempdir If returnwhat is "plot" then it returns the plot object as needed for table_xls_format()
- ...
other parameters passed through to
points()
See also
distance_by_group()
ejamit()
for examples
Examples
y <- ejamit(testpoints_100, radius = 3)
# see barplot and table comparing groups to see which are closer to sites analyzed
plot_distance_mean_by_group(y$results_bybg_people) # or distance_mean_by_group() synonym
# table - proximity of sites for just one demog group vs rest of population
print(distance_by_group(y$results_bybg_people,
demogvarname = 'pctlowinc'))
# plot cumulative share of group by distance vs overall population
distance_by_group_plot(y$results_bybg_people,
demogvarname = 'pctlowinc' )
# plot cum. shares for two groups
# about 14% of black and 12% of asian residents have a site within 1 mile.
# 29% vs 21% have a site within 1.5 miles.
round(xyz[findInterval(c(1, 1.5), xyz$dist), ], 3)
# plot is too busy for all groups at once so this is a way to tap through them 1 by 1
these = c(names_d, names_d_subgroups)
for (i in 1:length(these)) {
readline("press any key to see the next plot")
print(distance_by_group_plot(y$results_bybg_people, demogvarname = these[i]) )
}