make.popup.e: Make text to be shown in popups on Envt data map

View source: R/make.popup.e.R

make.popup.eR Documentation

Make text to be shown in popups on Envt data map

Description

Takes raw values and what percentiles they are at, and presents those as a text field to be used as text in a popup on a map

Usage

make.popup.e(e, pctile, prefix = "pctile.text.", basenames, units, sigfigs)

Arguments

e

raw environmental indicator values for various locations

pctile

required integers 0 to 100, representing the percentile(s) at which the raw value(s) fall(s).

prefix

optional, default is 'pctile.text.' This is a text string specifying the first part of the desired resulting fieldname in outputs.

basenames

optional, default is colnames(e). Defines colname(s) of outputs, which are the prefix plus this.

units

optional character vector with one per column of e, default is the units used for the latest (2016) version of EJSCREEN environmental indicators, such as 'ppb' and 'ug/m3' – function will try to use units appropriate to basenames, looking in data(popupunits), and use ” (blank) if no match is found.

sigfigs

optional, numeric vector with one per col of e, defining number of significant digits to show in popup, defaulting to rules in EJSCREEN latest (2016) version, or just 2 for basenames not found in data(esigfigs).

Details

Could edit code to NOT put in the units when value is NA?
Could edit code to handle cases like only one row, matrix not df?
Could fix to use only one space when no units

EJSCREEN as of 2015 used 85 pctile.text. fields, for popup text, like "pctile.text.EJ.DISPARITY.pm.eo"
names(bg2)[grepl('pctile.text', names(bg2) )] length( bg2[1, grepl('pctile.text', names(bg2) )] ) # [1] 85

In EJSCREEN, there are 3 types of pctile.text fields: E (text varies), D, EJ:
'pctile.text.cancer' "55 lifetime risk per million (91 'pctile.text.pctmin' "13 'pctile.text.EJ.DISPARITY.cancer.eo' "36 } For E popups, text includes units:\cr (neuro was only in 2015 version, not later versions of EJSCREEN)\cr\cr \code{ names.e.pctile[names.e.pctile != 'pctile.neuro'] # [1] "pctile.pm" "pctile.o3" "pctile.cancer" # [4] "pctile.resp" "pctile.dpm" "pctile.pctpre1960" # [7] "pctile.traffic.score" "pctile.proximity.npl" "pctile.proximity.rmp" # [10] "pctile.proximity.tsdf" "pctile.proximity.npdes" } # NOTE HOW UNITS ARE PART OF THE POPUP, AND IT USES SPECIAL ROUNDING RULES \cr # #' # Stored in data('popunits') # colnames are evar and units \cr\cr \code{ t(bg2[1,gsub('pctile','pctile.text', names.e.pctile[names.e.pctile != 'pctile.neuro'])]) # # pctile.text.pm "10.4 ug/m3 (76 # pctile.text.o3 "42.8 ppb (22%ile)" # pctile.text.cancer "55 lifetime risk per million (91%ile)" # pctile.text.resp "2.1 (72%ile)" # pctile.text.dpm "0.401 ug/m3 (24%ile)" # pctile.text.pctpre1960 "0.4 = fraction pre-1960 (68%ile)" # pctile.text.traffic.score "23 daily vehicles/meters distance (28%ile)" # pctile.text.proximity.npl "0.071 sites/km distance (55%ile)" # pctile.text.proximity.rmp "0.085 facilities/km distance (21%ile)" # pctile.text.proximity.tsdf "0 facilities/km distance (26%ile)" # pctile.text.proximity.npdes "0.25 facilities/km distance (70%ile)" # t(bg2[125:126, gsub('pctile', 'pctile.text', names.e.pctile[names.e.pctile != 'pctile.neuro'])]) # 125 126 # pctile.text.pm "8.37 ug/m3 (27%ile)" NA # pctile.text.o3 "41.7 ppb (19%ile)" NA # pctile.text.cancer "36 lifetime risk per million (37%ile)" NA # pctile.text.resp "1.4 (37%ile)" NA # pctile.text.dpm "0.275 ug/m3 (13%ile)" NA # pctile.text.pctpre1960 "0.055 = fraction pre-1960 (27%ile)" "0 = fraction pre-1960 (10 # pctile.text.traffic.score "1.7 daily vehicles/meters distance (6 "0 daily vehicles/meters distance (2 # pctile.text.proximity.npl "0.056 sites/km distance (47 "0 sites/km distance (16 # pctile.text.proximity.rmp "0.046 facilities/km distance (7 "0 facilities/km distance (1 # pctile.text.proximity.tsdf "0 facilities/km distance (26 "0 facilities/km distance (26 # pctile.text.proximity.npdes "0.067 facilities/km distance (16 "0 facilities/km distance (1 # # single result, e.g.: "24

Value

Returns character vector or data.frame, same shape as first input parameter.

See Also

esigfigs make.popup.d make.popup.e make.popup.ej pctileAsText

Examples

    #   Example: inputs are test0 and test1, and desired output is like test2
    #   (except note how prefix is added to each basename)

  test0 <- structure(list(
    e1 = c(0.185525372063833, 0.174428104575163, 0.485647788983707),
    e2 = c(0.131656804733727, 0.111928104575163, 0.671062839410395),
    other = c(NA, NA, 0.02)),
    .Names = c("e1", "e2", "other"),
    row.names = c(NA, 3L), class = "data.frame")
  test0

   test1 <- structure(list(
     pctile.e1 = c(27.1991395138354, 24.6836238179206, 72.382419748292),
     pctile.e2 = c(30.2662374847936, 26.761078397073, 78.2620665123235),
     other = c(NA, NA, 4)),
     .Names = c("pctile.e1", "pctile.e2", "other"),
     row.names = c(NA, 3L), class = "data.frame")
   test1

  test2 <- structure(list(
    pctile.text.e1 = c("19 (27%ile)", "17 (24%ile)","49 (72%ile)"),
    pctile.text.e2 = c("13 (30%ile)", "11 (26%ile)", "67 (78%ile)"),
    other = c(NA, NA, 4)),
    .Names = c("pctile.text.e1","pctile.text.e2", "other"),
    row.names = c(NA, 3L), class = "data.frame")
  test2

  ## make.popup.e(test0, test1)


ejanalysis/ejscreen documentation built on April 2, 2024, 10:15 a.m.