Skip to content

Commit

Permalink
Merge branch 'rm_346' into shiny_review
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinamullin committed Feb 22, 2024
2 parents 890e613 + 98d6ed2 commit 40a3f7b
Show file tree
Hide file tree
Showing 16 changed files with 619 additions and 170 deletions.
11 changes: 9 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ Package: TADA
Type: Package
Title: TADA (Tools for Automated Data Analysis) R Package
Version: 0.0.1
Organization: U.S. Environmental Protection Agency
Authors@R:
c(person(given = "Cristina",
c(person(given = "U.S. Environmental Protection Agency",
role = "aut"),
person(given = "Cristina",
family = "Mullin",
role = c("aut", "cre"),
email = "[email protected]",
Expand All @@ -15,6 +16,9 @@ Authors@R:
person(given = "Elise",
family = "Hinman",
role = "aut"),
person(given = "Hillary",
family = "Marler",
role = "aut"),
person(given = "Kathleen",
family = "Healy",
role = "aut"),
Expand All @@ -24,6 +28,9 @@ Authors@R:
person(given = "Laura",
family = "Decicco",
role = "ctb"),
person(given = "Renae",
family = "Myers",
role = "aut"),
person(given = "Brad",
family = "Cooper",
role = "ctr"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ export(TADA_Stats)
export(TADA_SubstituteDeprecatedChars)
export(TADA_SummarizeColumn)
export(TADA_TwoCharacteristicScatterplot)
export(TADA_addPoints)
export(TADA_addPolys)
importFrom(magrittr,"%>%")
35 changes: 30 additions & 5 deletions R/Figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ TADA_Histogram <- function(.data, id_cols = c("TADA.ComparableDataIdentifier"))
#' @return A leaflet map that shows all sites in the data frame, where larger point sizes
#' indicate more results collected at a site, and darker point colors indicate more
#' characteristics measured at that site. Users can click on points on the map to see
#' a pop-up window with exact counts for measurements, visits, and characteristics
#' associated with each site.
#' a pop-up window with exact counts for measurements (i.e. number of rows),
#' visits (number of unique Activity ID's), and characteristics associated with each site.
#'
#' @export
#'
Expand All @@ -395,12 +395,11 @@ TADA_OverviewMap <- function(.data) {
return(leaflet::addLegend(map, colors = colorAdditions, labels = labelAdditions, opacity = opacity, title = "Measurements"))
}


sumdat <- .data %>%
dplyr::group_by(MonitoringLocationIdentifier, MonitoringLocationName, TADA.LatitudeMeasure, TADA.LongitudeMeasure) %>%
dplyr::summarise("Sample_Count" = length(unique(ResultIdentifier)), "Visit_Count" = length(unique(ActivityStartDate)), "Parameter_Count" = length(unique(TADA.CharacteristicName)), "Organization_Count" = length(unique(OrganizationIdentifier)))

pt_sizes <- round(quantile(sumdat$Sample_Count, probs = c(0.1, 0.25, 0.5, 0.75)), 0)
pt_sizes <- round(stats::quantile(sumdat$Sample_Count, probs = c(0.1, 0.25, 0.5, 0.75)), 0)
pt_labels <- c(
paste0("<=", pt_sizes[1]),
paste0(">", pt_sizes[1]),
Expand All @@ -424,10 +423,25 @@ TADA_OverviewMap <- function(.data) {
domain = sumdat$Parameter_Count
)

# Tribal layers will load by default in the overview map, restricted by the bounding box of the current dataset
# They can be toggled on and off using a button (all layers work together and can't be turned on/off individually).
# Colors and icons are as discussed previously (orange/tan colors and open triangle icons for points) but can be changed to match HMW if desired.
bbox <- sf::st_bbox(
c(
xmin = min(sumdat$TADA.LongitudeMeasure),
ymin = min(sumdat$TADA.LatitudeMeasure),
xmax = max(sumdat$TADA.LongitudeMeasure),
ymax = max(sumdat$TADA.LatitudeMeasure)
),
crs = sf::st_crs(sumdat)
)
vbbox <- bbox %>%
as.vector()

map <- leaflet::leaflet() %>%
leaflet::addProviderTiles("Esri.WorldTopoMap", group = "World topo", options = leaflet::providerTileOptions(updateWhenZooming = FALSE, updateWhenIdle = TRUE)) %>%
leaflet::clearShapes() %>% # get rid of whatever was there before if loading a second dataset
leaflet::fitBounds(lng1 = min(sumdat$TADA.LongitudeMeasure), lat1 = min(sumdat$TADA.LatitudeMeasure), lng2 = max(sumdat$TADA.LongitudeMeasure), lat2 = max(sumdat$TADA.LatitudeMeasure)) %>% # fit to bounds of data in tadat$raw
leaflet::fitBounds(lng1 = vbbox[1], lat1 = vbbox[2], lng2 = vbbox[3], lat2 = vbbox[4]) %>% # fit to bounds of data in tadat$raw
leaflet.extras::addResetMapButton() %>% # button to reset to initial zoom and lat/long
leaflet::addCircleMarkers(
data = sumdat,
Expand Down Expand Up @@ -457,6 +471,17 @@ TADA_OverviewMap <- function(.data) {
colors = "black",
labels = site_legend$Sample_n, sizes = site_legend$Point_size * 2
)
# TADA_addPolys and TADA_addPoints are in Utilities.R
map <- TADA_addPolys(map, AKAllotmentsUrl, "Tribes", "Alaska Allotments", bbox)
map <- TADA_addPolys(map, AmericanIndianUrl, "Tribes", "American Indian", bbox)
map <- TADA_addPolys(map, OffReservationUrl, "Tribes", "Off Reservation", bbox)
map <- TADA_addPolys(map, OKTribeUrl, "Tribes", "Oklahoma Tribe", bbox)
map <- TADA_addPoints(map, AKVillagesUrl, "Tribes", "Alaska Native Villages", bbox)
map <- TADA_addPoints(map, VATribeUrl, "Tribes", "Virginia Tribe", bbox)
map <- leaflet::addLayersControl(map,
overlayGroups = c("Tribes"),
options = leaflet::layersControlOptions(collapsed = FALSE)
)
return(map)
})
}
Expand Down
6 changes: 3 additions & 3 deletions R/RequiredCols.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ require.cols <- c(
"TADA.ResultMeasure.MeasureUnitCode", # generated/required/replaces original
"TADA.WQXResultUnitConversion", # generated, only added when transform = FALSE in TADA_ConvertResultUnits
"TADA.WQXTargetUnit", # generated, only added when transform = FALSE in TADA_ConvertResultUnits
"Target.TADA.ResultMeasure.MeasureUnitCode",
"Target.TADA.UnitConversionFactor", # generated when
"Target.TADA.ResultMeasure.MeasureUnitCode",
"Target.TADA.UnitConversionFactor", # generated when
"TADA.WQXUnitConversionFactor", # generated, only added when transform = FALSE in TADA_ConvertResultUnits
"Target.TADA.UnitConversionCoefficient",
"TADA.UnitConversionFactor", # generated, added from TADA harmonization template
Expand Down Expand Up @@ -307,7 +307,7 @@ TADA_OrderCols <- function(.data) {
#'
TADA_GetTemplate <- function() {
data(Data_Nutrients_UT)
examplerow <- head(Data_Nutrients_UT, 1)
examplerow <- utils::head(Data_Nutrients_UT, 1)
examplerow2 <- subset(examplerow, select = names(examplerow) %in% require.cols)
writexl::write_xlsx(examplerow2, path = "TADATemplate.xlsx")
}
Expand Down
Loading

0 comments on commit 40a3f7b

Please sign in to comment.