Skip to content

Commit

Permalink
Merge pull request #348 from USEPA/plotfix2
Browse files Browse the repository at this point in the history
Fixes plotting issues
  • Loading branch information
cristinamullin authored Oct 26, 2023
2 parents 7c84058 + 0ed1fa6 commit 65b6bc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
42 changes: 21 additions & 21 deletions R/Figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ TADA_Boxplot <- function(.data, id_cols = c("TADA.ComparableDataIdentifier")) {
TADA_CheckColumns(.data, id_cols)

# check .data has required columns
TADA_CheckColumns(.data, c("TADA.ResultMeasureValue", "TADA.ResultMeasure.MeasureUnitCode"))
TADA_CheckColumns(.data, c("TADA.ResultMeasureValue",
"TADA.ResultMeasure.MeasureUnitCode"))

start <- dim(.data)[1]

Expand Down Expand Up @@ -232,21 +233,13 @@ TADA_Histogram <- function(.data, id_cols = c("TADA.ComparableDataIdentifier"))
warning("TADA.ComparableDataIdentifier not found in id_cols argument and is highly recommended: plotting without it may produce errors in the plot.")
}

req_cols <- c(
"TADA.ComparableDataIdentifier",
"TADA.CharacteristicName",
"TADA.ResultSampleFractionText",
"TADA.MethodSpecificationName",
"TADA.ResultMeasure.MeasureUnitCode",
"TADA.ResultMeasureValue",
"ActivityStartDate",
"MonitoringLocationIdentifier",
"ActivityTypeCode"
)
# check .data has required columns
TADA_CheckColumns(.data, id_cols)

# check .data has required columns
TADA_CheckColumns(.data, expected_cols = req_cols)

TADA_CheckColumns(.data, c("TADA.ResultMeasureValue",
"TADA.ResultMeasure.MeasureUnitCode"))

start <- dim(.data)[1]

.data <- subset(.data, !is.na(.data$TADA.ResultMeasureValue))
Expand Down Expand Up @@ -549,11 +542,13 @@ TADA_Scatterplot <- function(.data, id_cols = c("TADA.ComparableDataIdentifier")
warning("TADA.ComparableDataIdentifier not found in id_cols argument and is highly recommended: plotting without it may produce errors in the plot.")
}

# check .data has required columns
TADA_CheckColumns(.data, id_cols)

# check .data has required columns
TADA_CheckColumns(.data, c("ActivityStartDate",
"TADA.ResultMeasureValue",
"TADA.ResultMeasure.MeasureUnitCode",
"TADA.ComparableDataIdentifier"))
"TADA.ResultMeasure.MeasureUnitCode"))

.data <- .data %>%
dplyr::group_by(dplyr::across(dplyr::all_of(id_cols))) %>%
Expand Down Expand Up @@ -590,11 +585,13 @@ TADA_Scatterplot <- function(.data, id_cols = c("TADA.ComparableDataIdentifier")
"Activity Start Date:", plot.data$ActivityStartDate, "<br>",
"Activity Start Date Time:", plot.data$ActivityStartDateTime, "<br>",
"Monitoring Location Name:", plot.data$MonitoringLocationName, "<br>",
"Media:", plot.data$TADA.ActivityMediaName, "<br>",
"Media Subdivision:", plot.data$ActivityMediaSubdivisionName, "<br>",
"Result Depth:", paste0(
plot.data$TADA.ResultDepthHeightMeasure.MeasureValue, " ",
plot.data$TADA.ResultDepthHeightMeasure.MeasureUnitCode
), "<br>",
"Activity Relative Depth Name:", plot.data$ActivityRelativeDepthName, "<br>",
"Activity Relative Depth:", plot.data$ActivityRelativeDepthName, "<br>",
"Activity Depth:", paste0(
plot.data$TADA.ActivityDepthHeightMeasure.MeasureValue, " ",
plot.data$TADA.ActivityDepthHeightMeasure.MeasureUnitCode
Expand Down Expand Up @@ -697,13 +694,12 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
TADA_CheckType(.data, "data.frame", "Input object")

# check .data has required columns
TADA_CheckColumns(.data, id_cols)

# check .data has required columns
reqcols <- c("TADA.ResultMeasureValue",
"TADA.ResultMeasure.MeasureUnitCode",
"ActivityStartDate",
"ActivityStartDateTime",
"TADA.ComparableDataIdentifier",
"MonitoringLocationName")
"ActivityStartDate")

# check .data has required columns
TADA_CheckColumns(.data, reqcols)
Expand Down Expand Up @@ -784,6 +780,8 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
"Activity Start Date:", param1$ActivityStartDate, "<br>",
"Activity Start Date Time:", param1$ActivityStartDateTime, "<br>",
"Monitoring Location Name:", param1$MonitoringLocationName, "<br>",
"Media:", param1$TADA.ActivityMediaName, "<br>",
"Media Subdivision:", param1$ActivityMediaSubdivisionName, "<br>",
"Result Depth:", paste0(
param1$TADA.ResultDepthHeightMeasure.MeasureValue, " ",
param1$TADA.ResultDepthHeightMeasure.MeasureUnitCode
Expand Down Expand Up @@ -811,6 +809,8 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
"Activity Start Date:", param2$ActivityStartDate, "<br>",
"Activity Start Date Time:", param2$ActivityStartDateTime, "<br>",
"Monitoring Location Name:", param2$MonitoringLocationName, "<br>",
"Media:", param2$TADA.ActivityMediaName, "<br>",
"Media Subdivision:", param2$ActivityMediaSubdivisionName, "<br>",
"Result Depth:", paste0(
param2$TADA.ResultDepthHeightMeasure.MeasureValue, " ",
param2$TADA.ResultDepthHeightMeasure.MeasureUnitCode
Expand Down
2 changes: 1 addition & 1 deletion R/Tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TADA_SummarizeColumn <- function(.data, col = "TADA.CharacteristicName") {
TADA_Stats <- function(.data, group_cols = c("TADA.ComparableDataIdentifier")) {
if (any(is.na(.data$TADA.ResultMeasureValue))) {
sumNAs <- length(.data$TADA.ResultMeasureValue[is.na(.data$TADA.ResultMeasureValue)])
warning(paste0("Dataset contains ", sumNAs, " results missing both a TADA result value and a detection limit. These values will not be represented in the summary table. Suggest removing or handling."))
print(paste0("Dataset contains ", sumNAs, " results missing both a TADA result value and a detection limit. These values will not be represented in the stats summary table. Suggest removing or handling."))
}

if (!"TADA.CensoredData.Flag" %in% names(.data)) {
Expand Down
4 changes: 3 additions & 1 deletion R/Transformations.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,14 @@ TADA_CalculateTotalNP <- function(.data, sum_ref, daily_agg = c("max", "min", "m
depths <- names(.data)[grepl("DepthHeightMeasure", names(.data))]
depths <- depths[grepl("TADA.", depths)]
grpcols <- c("ActivityStartDate",
"ActivityStartDateTime",
#"ActivityStartDateTime", #does not make sense to include for daily agg
"ActivityRelativeDepthName",
"MonitoringLocationIdentifier",
"MonitoringLocationName",
"TADA.LongitudeMeasure",
"TADA.LatitudeMeasure",
"ActivityMediaSubdivisionName",
"TADA.ActivityMediaName",
"TADA.ComparableDataIdentifier",
"TADA.ResultMeasure.MeasureUnitCode",
depths)
Expand Down

0 comments on commit 65b6bc3

Please sign in to comment.