Skip to content

Commit

Permalink
Merge pull request #349 from USEPA/hovertext
Browse files Browse the repository at this point in the history
populate scatter2 hoover text
  • Loading branch information
cristinamullin authored Oct 26, 2023
2 parents 65b6bc3 + fd77ea5 commit 197f948
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions R/Figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
id_cols <- "TADA.ComparableDataIdentifier"
}

# if (!"TADA.ComparableDataIdentifier" %in% id_cols) {
# warning("TADA.ComparableDataIdentifier not found in id_cols argument and is highly recommended: plotting without it may produce errors in the plot.")
# }
if (!"TADA.ComparableDataIdentifier" %in% id_cols) {
print("Note: TADA.ComparableDataIdentifier not found in id_cols argument and is highly recommended.")
}

# check that groups are in id_cols
id <- unlist(unique(.data[, id_cols]))
Expand All @@ -724,7 +724,8 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD

plot.data <- as.data.frame(.data)

plot.data <- subset(plot.data, plot.data[, id_cols] %in% groups)[, c(id_cols, reqcols, depthcols)]
# this subset must include all fields included in plot hover below
plot.data <- subset(plot.data, plot.data[, id_cols] %in% groups)[, c(id_cols, reqcols, depthcols, "ActivityStartDateTime", "MonitoringLocationName", "TADA.ActivityMediaName", "ActivityMediaSubdivisionName", "ActivityRelativeDepthName", "TADA.CharacteristicName")]
plot.data$name <- gsub("_NA", "", plot.data[, id_cols])
plot.data$name <- gsub("_", " ", plot.data$name)

Expand All @@ -733,7 +734,7 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
param1 <- subset(plot.data, plot.data[, id_cols] %in% groups[1])
param2 <- subset(plot.data, plot.data[, id_cols] %in% groups[2])

title <- TADA::TADA_InsertBreaks(paste0("Scatterplot of ", param1$name[1], " and ", param2$name[1]), len = 60)
title <- TADA::TADA_InsertBreaks(paste0("Scatterplot of ", param1$name[1], " and ", param2$name[1]), len = 40)

# figure margin
mrg <- list(
Expand Down Expand Up @@ -773,7 +774,13 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
# config options https://plotly.com/r/configuration-options/
plotly::config(displaylogo = FALSE) %>% #, displayModeBar = TRUE) # TRUE makes bar always visible
plotly::add_trace(
data = param1, x = ~ActivityStartDate, y = ~TADA.ResultMeasureValue, name = param1$name, marker = list(size = 10, color = "#E34234", line = list(color = "#005ea2", width = 2)),
data = param1,
x = ~ActivityStartDate,
y = ~TADA.ResultMeasureValue,
name = param1$TADA.CharacteristicName,
marker = list(size = 10,
color = "#E34234",
line = list(color = "#005ea2", width = 2)),
hoverinfo = "text",
hovertext = paste(
"Result:", paste0(param1$TADA.ResultMeasureValue, " ", param1$TADA.ResultMeasure.MeasureUnitCode), "<br>",
Expand Down Expand Up @@ -802,7 +809,13 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
)
) %>%
plotly::add_trace(
data = param2, x = ~ActivityStartDate, y = ~TADA.ResultMeasureValue, name = param2$name, marker = list(size = 10, color = "#00bde3", line = list(color = "#005ea2", width = 2)), yaxis = "y2",
data = param2,
x = ~ActivityStartDate,
y = ~TADA.ResultMeasureValue,
name = param2$TADA.CharacteristicName,
marker = list(size = 10, color = "#00bde3",
line = list(color = "#005ea2", width = 2)),
yaxis = "y2",
hoverinfo = "text",
hovertext = paste(
"Result:", paste0(param2$TADA.ResultMeasureValue, " ", param2$TADA.ResultMeasure.MeasureUnitCode), "<br>",
Expand Down

0 comments on commit 197f948

Please sign in to comment.