Map - Create leaflet html widget map from ejamit() output or a table of point coordinates, polygons, or fips
Source:R/mapfast.R
mapfast.RdMap - Create leaflet html widget map from ejamit() output or a table of point coordinates, polygons, or fips
Usage
mapfast(
mydf,
radius = 3,
column_names = "all",
labels = column_names,
launch_browser = FALSE,
color = "#03F",
sitenumber_label = NULL,
popup_style = "auto",
cluster = NULL
)Arguments
- mydf
Typically something like the output of ejamit()$results_bysite, but can also be the full output of
ejamit()in which case this uses just the $results_bysite table, and in general mydf can be a data.frame or table in data.table format that has a set of points or polygons or Census FIPS codes.point data defined by columns named lat and lon, or columns that
latlon_infer()can infer to be that, as fromsitepoints_from_any()orejamit()$results_bysitepolygon data in a spatial data.frame that has a geometry column of polygons, as from
shapefile_from_any(), orCensus units defined by FIPS codes in a column called "ejam_uniq_id" (not fips), where those fips are for States, Counties, Tracts, Blockgroups, or cities/towns/Census Designated Places (7 digits including any leading zeroes), e.g., as from
names2fips('DE')orejamit(fips='01')$results_bysite.
- radius
in miles, converted to meters and passed to
leaflet::addCircles()if appropriate. If not provided, function tries to find it in mydf (in case that is output of ejamit() for example)- column_names
If "ej" then nice popup made based on just key EJSCREEN indicators. If "all" then every column in the entire mydf table is shown in the popup. If a vector of colnames, only those are shown in popups.
- labels
The labels used before the column_names, for map popups, like label: column_name (ignored if column_names is ej or all)
- launch_browser
optional logical, set to TRUE if you want the function to launch a default browser window to show the map and print the temp filepath and filename in the console. Normally the map would be shown in the default RStudio viewer pane.
- color
A column name in mydf (or its results_bysite table), a single R color, or one color per row, for circles or polygons. Percentile and ratio columns use the shared binned colors; other numeric columns use a continuous viridis palette. An unknown column name that is not a valid R color causes an error. Missing values in a color column are shown in light gray. These maps do not automatically add a color legend; use
mapfastej_counties()for a county choropleth with a percentile legend.- sitenumber_label
optional, display-only override (a number or short text) of the site number shown in map popups, in place of the auto-assigned row number/ejam_uniq_id. Passed to
popup_from_ejscreen()(so used only if column_names is "ej"), and only relevant when mydf is a single-site (1-row) table – seeejam2report(), whose sitenumber_label parameter this supports.- popup_style
"auto","full","short", or"none". Seemap_popup_style()."auto"gives short popups (if column_names is "ej") when there are more thandefault_max_pts_show_detailed_popupssites (seemap_size_setting())."none"maps the sites without popups.- cluster
TRUE to show points as clustered markers instead of circles. The default, NULL, clusters them when there are more than
default_max_pts_map_show_unclusteredpoints (seemap_size_setting()).
Value
plots a map via the leaflet package, with popups with all the columns from mydf, and returns html widget
Details
Blockgroup FIPS maps explicitly use cached, generalized cartographic boundaries for speed. These simplify edges and shorelines and are intended for overview maps. For detailed boundaries, supply polygons obtained with shapes_from_fips(fips, myservice_blockgroup = "tiger", year = acs_endyear()). This display choice does not change the analysis that produced the results.
Examples
pts <- testpoints_100
pts <- pts[is.finite(pts$lat) & is.finite(pts$lon), ]
mapfast(pts)
# out = ejamit(pts, radius = 1)
out <- testoutput_ejamit_100pts_1miles
# Use valid sites so the color vector matches the rows being mapped.
out$results_bysite <- out$results_bysite[out$results_bysite$valid %in% TRUE, ]
# See in RStudio viewer pane
ejam2map(out, launch_browser = FALSE)
# Color by a percentile column without manually converting its values.
ejam2map(out, color = "state.pctile.o3", launch_browser = FALSE)
mapfastej(out$results_bysite[c(12,31),])
# color-code points on map to show which ones had a high indicator score
mapfastej(out, color = EJAM:::ratio2color( out$results_bysite$ratio.to.state.avg.traffic.score))
mapfastej(out, color = EJAM:::pctile2color( out$results_bysite$state.pctile.o3))
mapfastej(out, color = EJAM:::pctile2color(out$results_bysite$pctile.Demog.Index.Supp))
if (FALSE) { # \dontrun{
out <- ejamit(fips = fips_counties_from_state_abbrev(c('KY', 'IN')))
ejam2map(out, color = EJAM:::pctile2color( out$results_bysite$state.pctile.o3))
# See in local browser instead
ejam2map(out)
# Open folder where interactive map
# .html file is saved, so you can share it:
x = ejam2map(out)
fname = map2browser(x)
# browseURL(normalizePath(dirname(fname))) # to open the temp folder
# file.copy(fname, "./map.html") # to copy map file to working directory
} # }