Skip to content

Commit

Permalink
Merge pull request #498 from USEPA/467-add-an-all-others-category-to-…
Browse files Browse the repository at this point in the history
…tada_fieldvaluespie-when-there-are-many-categories

467-add-an-all-others-category-to-tada_fieldvaluespie-when-there-are-many-categories
  • Loading branch information
hillarymarler authored Jul 15, 2024
2 parents b126e29 + 3c2c999 commit 3f4b630
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Copyright: This software is in the public domain because it contains materials
that originally came from the U.S. Environmental Protection Agency.
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
plyr,
data.table,
Expand Down
17 changes: 14 additions & 3 deletions R/Figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,26 @@ TADA_FlaggedSitesMap <- function(.data) {
#' # Create a list of parameters in the dataset and the number of records of
#' # each parameter:
#' TADA_FieldValuesPie(Data_Nutrients_UT, field = "TADA.CharacteristicName")
#' # If there are more than 12 categories to display, any remaining categories, the ones that have the smallest number of results,
#' # are combined into an "ALL OTHERS" category.
#' TADA_FieldValuesPie(Data_Nutrients_UT, field = "TADA.ComparableDataIdentifier")
#'
TADA_FieldValuesPie <- function(.data, field = "null", characteristicName = "null") {
dat <- TADA_FieldValuesTable(.data = .data, field = field, characteristicName = characteristicName)

dat <- head(TADA_FieldValuesTable(.data = .data, field = field, characteristicName = characteristicName), 12)
# If data set contains more than 12 categories, dat2 aggregates 'all other' categories into its own row.
dat2 <- data.frame(Value = "ALL OTHERS", Count = sum(TADA_FieldValuesTable(.data = .data, field = field, characteristicName = characteristicName)[-(1:12),][2]))

dat$Legend <- paste0(dat$Value, " - ", dat$Count, " results")
dat2$Legend <- paste0(dat2$Value, " - ", dat2$Count, " results")
dat <- dat %>%
dplyr::rowwise() %>%
dplyr::mutate(Legend = TADA_InsertBreaks(Legend))


# Only apply the all others category if there are greater than 12 categories to display.
if(dat2$Count != 0) {
dat <- dplyr::bind_rows(dat, dat2)
}

# create TADA color palette
tada.pal <- TADA_ColorPalette()

Expand Down
3 changes: 3 additions & 0 deletions man/TADA_FieldValuesPie.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f4b630

Please sign in to comment.