Input data:
data <- read_xlsx("/Users/Alan/__PythonProjects/DownloadProject/Trib3A_Compare.xlsx",
- col_names = TRUE) %>%
- select(datetime,LowerWaterLevel,UpperEC,LowerEC)
data$Chloride <- data$LowerEC*0.3117
Check the format, it is not a date yet !
str(data)
tibble [1,006 × 5] (S3: tbl_df/tbl/data.frame)
$ datetime : POSIXct[1:1006], format: "2025-01-30 20:40:00" "2025-01-30 20:50:00" "2025-01-30 21:00:00" "2025-01-30 21:10:00" ...
$ LowerWaterLevel: num [1:1006] 256 254 254 253 253 254 256 258 261 264 ...
$ UpperEC : num [1:1006] 2193 2138 1841 1611 1452 ...
$ LowerEC : num [1:1006] 1892 1977 1845 1722 1618 ...
$ Chloride : num [1:1006] 590 616 575 537 504 ...
Case 1
Case 1.png
Looks OK, but I wanted to show the Chloride numbers on y2 as the whole numbers they were in the input data. [aside: Issue #180 "Axis reversed with dyStackedBarGroup() " shows the same 2 decimal places on y2 axis.]
dygraph(dataXTS, main = "Compare Conductivity at streambed surface and at 25 cm in the gravel") %>%
dySeries("LowerEC", label = "LowerEC", color = "green") %>%
dySeries("UpperEC", label = "UpperEC", color = "blue") %>%
dySeries("LowerWaterLevel", label = "LowerWaterLevel", color = "black", strokeWidth = 2, strokePattern = "dashed") %>%
dySeries("Chloride", label = "Lower Chloride (mg / L)", color = "red", strokeWidth = 2, strokePattern = "dashed", axis = "y2") %>%
dyEvent("2025-02-01 9:50", "Start of nearby salting", labelLoc = "top") %>%
dyOptions(labelsUTC = TRUE, fillGraph = TRUE, fillAlpha = 0.1, drawGrid = TRUE) %>%
dyAxis("x", label = "2025", logscale = TRUE, valueRange = c(20, 20000)) %>%
dyAxis("y", label = "Lower Conductivity µS / cm", logscale = TRUE, valueRange = c(100, 20000)) %>%
dyAxis("y2", label = "Chloride (mg / L)", logscale = TRUE, valueRange = c(100, 5000)) %>%
dyLimit(limit = 500, label = "BC Chronic Water Quality Guideline for Cl (150 mg / L)", labelLoc = c("left", "right"),
color = "orange", strokePattern = "dashed") %>%
dyLimit(limit = 2000, label = "BC Acute Water Quality Guideline for Cl (600 mg / L)", labelLoc = c("left", "right"),
color = "red", strokePattern = "dashed") %>%
dyLegend(show = "always") %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyCrosshair(direction = "vertical") %>%
dyRangeSelector(height = 20)
Case 2
Case 2.png
Changed dyAxis("y2", label = "Chloride (mg / L)", logscale = FALSE
This forced both y and y2 to be linear! Still shows the same 2 decimal places on y2 axis.
dygraph(dataXTS, main = "Compare Conductivity at streambed surface and at 25 cm in the gravel") %>%
dySeries("LowerEC", label = "LowerEC", color = "green") %>%
dySeries("UpperEC", label = "UpperEC", color = "blue") %>%
dySeries("LowerWaterLevel", label = "LowerWaterLevel", color = "black", strokeWidth = 2, strokePattern = "dashed") %>%
dySeries("Chloride", label = "Lower Chloride (mg / L)", color = "red", strokeWidth = 2, strokePattern = "dashed", axis = "y2") %>%
dyEvent("2025-02-01 9:50", "Start of nearby salting", labelLoc = "top") %>%
dyOptions(labelsUTC = TRUE, fillGraph = TRUE, fillAlpha = 0.1, drawGrid = TRUE) %>%
dyAxis("x", label = "2025", logscale = TRUE, valueRange = c(20, 20000)) %>%
dyAxis("y", label = "Lower Conductivity µS / cm", logscale = TRUE, valueRange = c(100, 20000)) %>%
dyAxis("y2", label = "Chloride (mg / L)", logscale = FALSE, valueRange = c(100, 5000)) %>%
dyLimit(limit = 500, label = "BC Chronic Water Quality Guideline for Cl (150 mg / L)", labelLoc = c("left", "right"),
color = "orange", strokePattern = "dashed") %>%
dyLimit(limit = 2000, label = "BC Acute Water Quality Guideline for Cl (600 mg / L)", labelLoc = c("left", "right"),
color = "red", strokePattern = "dashed") %>%
dyLegend(show = "always") %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyCrosshair(direction = "vertical") %>%
dyRangeSelector(height = 20)
Case 3
Case 3.png
On the suggestion of Gemini, I used valueFormater. Still shows the same 2 decimal places on y2 axis.
dygraph(dataXTS, main = "Compare Conductivity at streambed surface and at 25 cm in the gravel") %>%
dySeries("LowerEC", label = "LowerEC", color = "green") %>%
dySeries("UpperEC", label = "UpperEC", color = "blue") %>%
dySeries("LowerWaterLevel", label = "LowerWaterLevel", color = "black", strokeWidth = 2, strokePattern = "dashed") %>%
dySeries("Chloride", label = "Lower Chloride (mg / L)", color = "red", strokeWidth = 2, strokePattern = "dashed", axis = "y2") %>%
dyEvent("2025-02-01 9:50", "Start of nearby salting", labelLoc = "top") %>%
dyOptions(labelsUTC = TRUE, fillGraph = TRUE, fillAlpha = 0.1, drawGrid = TRUE) %>%
dyAxis("x", label = "2025", logscale = FALSE, valueRange = c(20, 20000)) %>%
dyAxis("y", label = "Lower Conductivity µS / cm", logscale = FALSE, valueRange = c(100, 20000)) %>%
dyAxis("y2", label = "Chloride (mg / L)", logscale = FALSE, valueRange = c(100, 5000),
valueFormatter = 'function(y) { return Math.round(y); }')
dyLimit(limit = 500, label = "BC Chronic Water Quality Guideline for Cl (150 mg / L)", labelLoc = c("left", "right"),
color = "orange", strokePattern = "dashed") %>%
dyLimit(limit = 2000, label = "BC Acute Water Quality Guideline for Cl (600 mg / L)", labelLoc = c("left", "right"),
color = "red", strokePattern = "dashed") %>%
dyLegend(show = "always") %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyCrosshair(direction = "vertical") %>%
dyRangeSelector(height = 20)
Input data:
Case 1
Case 1.png
Looks OK, but I wanted to show the Chloride numbers on y2 as the whole numbers they were in the input data. [aside: Issue #180 "Axis reversed with dyStackedBarGroup() " shows the same 2 decimal places on y2 axis.]
dygraph(dataXTS, main = "Compare Conductivity at streambed surface and at 25 cm in the gravel") %>%
dySeries("LowerEC", label = "LowerEC", color = "green") %>%
dySeries("UpperEC", label = "UpperEC", color = "blue") %>%
dySeries("LowerWaterLevel", label = "LowerWaterLevel", color = "black", strokeWidth = 2, strokePattern = "dashed") %>%
dySeries("Chloride", label = "Lower Chloride (mg / L)", color = "red", strokeWidth = 2, strokePattern = "dashed", axis = "y2") %>%
dyEvent("2025-02-01 9:50", "Start of nearby salting", labelLoc = "top") %>%
dyOptions(labelsUTC = TRUE, fillGraph = TRUE, fillAlpha = 0.1, drawGrid = TRUE) %>%
dyAxis("x", label = "2025", logscale = TRUE, valueRange = c(20, 20000)) %>%
dyAxis("y", label = "Lower Conductivity µS / cm", logscale = TRUE, valueRange = c(100, 20000)) %>%
dyAxis("y2", label = "Chloride (mg / L)", logscale = TRUE, valueRange = c(100, 5000)) %>%
dyLimit(limit = 500, label = "BC Chronic Water Quality Guideline for Cl (150 mg / L)", labelLoc = c("left", "right"),
color = "orange", strokePattern = "dashed") %>%
dyLimit(limit = 2000, label = "BC Acute Water Quality Guideline for Cl (600 mg / L)", labelLoc = c("left", "right"),
color = "red", strokePattern = "dashed") %>%
dyLegend(show = "always") %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyCrosshair(direction = "vertical") %>%
dyRangeSelector(height = 20)
Case 2
Case 2.png
Changed dyAxis("y2", label = "Chloride (mg / L)", logscale = FALSE
This forced both y and y2 to be linear! Still shows the same 2 decimal places on y2 axis.
dygraph(dataXTS, main = "Compare Conductivity at streambed surface and at 25 cm in the gravel") %>%
dySeries("LowerEC", label = "LowerEC", color = "green") %>%
dySeries("UpperEC", label = "UpperEC", color = "blue") %>%
dySeries("LowerWaterLevel", label = "LowerWaterLevel", color = "black", strokeWidth = 2, strokePattern = "dashed") %>%
dySeries("Chloride", label = "Lower Chloride (mg / L)", color = "red", strokeWidth = 2, strokePattern = "dashed", axis = "y2") %>%
dyEvent("2025-02-01 9:50", "Start of nearby salting", labelLoc = "top") %>%
dyOptions(labelsUTC = TRUE, fillGraph = TRUE, fillAlpha = 0.1, drawGrid = TRUE) %>%
dyAxis("x", label = "2025", logscale = TRUE, valueRange = c(20, 20000)) %>%
dyAxis("y", label = "Lower Conductivity µS / cm", logscale = TRUE, valueRange = c(100, 20000)) %>%
dyAxis("y2", label = "Chloride (mg / L)", logscale = FALSE, valueRange = c(100, 5000)) %>%
dyLimit(limit = 500, label = "BC Chronic Water Quality Guideline for Cl (150 mg / L)", labelLoc = c("left", "right"),
color = "orange", strokePattern = "dashed") %>%
dyLimit(limit = 2000, label = "BC Acute Water Quality Guideline for Cl (600 mg / L)", labelLoc = c("left", "right"),
color = "red", strokePattern = "dashed") %>%
dyLegend(show = "always") %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyCrosshair(direction = "vertical") %>%
dyRangeSelector(height = 20)
Case 3
Case 3.png
On the suggestion of Gemini, I used valueFormater. Still shows the same 2 decimal places on y2 axis.
dygraph(dataXTS, main = "Compare Conductivity at streambed surface and at 25 cm in the gravel") %>%
dySeries("LowerEC", label = "LowerEC", color = "green") %>%
dySeries("UpperEC", label = "UpperEC", color = "blue") %>%
dySeries("LowerWaterLevel", label = "LowerWaterLevel", color = "black", strokeWidth = 2, strokePattern = "dashed") %>%
dySeries("Chloride", label = "Lower Chloride (mg / L)", color = "red", strokeWidth = 2, strokePattern = "dashed", axis = "y2") %>%
dyEvent("2025-02-01 9:50", "Start of nearby salting", labelLoc = "top") %>%
dyOptions(labelsUTC = TRUE, fillGraph = TRUE, fillAlpha = 0.1, drawGrid = TRUE) %>%
dyAxis("x", label = "2025", logscale = FALSE, valueRange = c(20, 20000)) %>%
dyAxis("y", label = "Lower Conductivity µS / cm", logscale = FALSE, valueRange = c(100, 20000)) %>%
dyAxis("y2", label = "Chloride (mg / L)", logscale = FALSE, valueRange = c(100, 5000),
valueFormatter = 'function(y) { return Math.round(y); }')
dyLimit(limit = 500, label = "BC Chronic Water Quality Guideline for Cl (150 mg / L)", labelLoc = c("left", "right"),
color = "orange", strokePattern = "dashed") %>%
dyLimit(limit = 2000, label = "BC Acute Water Quality Guideline for Cl (600 mg / L)", labelLoc = c("left", "right"),
color = "red", strokePattern = "dashed") %>%
dyLegend(show = "always") %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE) %>%
dyCrosshair(direction = "vertical") %>%
dyRangeSelector(height = 20)