Load Packages

library(tidyverse)
library(ggmap)
library(plotly)
library(leaflet)
library(sp)
knitr::opts_chunk$set(
        echo = TRUE,
        warning = FALSE,
  fig.width = 6,
  fig.asp = .6,
  out.width = "90%"
)

theme_set(theme_minimal() +theme(legend.position = "bottom"))

options(
  ggplot2.continuous.color = "viridis",
  ggplot2.continuous.fill = "viridis"
)

scale_color_discrete = scale_colour_viridis_d
scale_fill_discrete = scale_fill_viridis_d

Read in Data

elk = read.csv(file = "clean_data/elk.csv") |> 
  mutate(date = as.Date(paste(year, month, day, sep = "-")))

water_quality = read.csv(file = "clean_data/water_quality.csv") |> 
  mutate(date = as.Date(paste(year, month, day, sep = "-"))) |> 
  filter(location_id %in% c("GRTE_SNR01", "GRTE_SNR02", "YELL_LM000.5M", "YELL_YS549.7M", "YELL_MD133.2T", "YELL_MDR"))

Water Quality

  • The year, month, and day variables give the time.
  • The latitude and longitude give the location.
  • characteristic_name gives the type of measurement.
  • result_text gives the measurement.
head(water_quality)
##   location_id                                        location_name park_code
## 1  GRTE_SNR01 Snake River at Old Flagg Ranch 1000\x92 Below Bridge      GRTE
## 2  GRTE_SNR01 Snake River at Old Flagg Ranch 1000\x92 Below Bridge      GRTE
## 3  GRTE_SNR01 Snake River at Old Flagg Ranch 1000\x92 Below Bridge      GRTE
## 4  GRTE_SNR01 Snake River at Old Flagg Ranch 1000\x92 Below Bridge      GRTE
## 5  GRTE_SNR01 Snake River at Old Flagg Ranch 1000\x92 Below Bridge      GRTE
## 6  GRTE_SNR01 Snake River at Old Flagg Ranch 1000\x92 Below Bridge      GRTE
##   location_type latitude longitude                activity_id
## 1  River/Stream 44.10177 -110.6716 GRTE_SNR01_060645226G42^01
## 2  River/Stream 44.10177 -110.6716 GRTE_SNR01_060645226G42^01
## 3  River/Stream 44.10177 -110.6716 GRTE_SNR01_060645226G42^01
## 4  River/Stream 44.10177 -110.6716 GRTE_SNR01_060650226G41^01
## 5  River/Stream 44.10177 -110.6716 GRTE_SNR01_060650226G41^01
## 6  River/Stream 44.10177 -110.6716 GRTE_SNR01_060650226G41^01
##                            activity_type activity_start_date year month day
## 1 Quality Control Sample-Equipment Blank          2006-08-14 2006     8  14
## 2 Quality Control Sample-Equipment Blank          2006-08-14 2006     8  14
## 3 Quality Control Sample-Equipment Blank          2006-08-14 2006     8  14
## 4      Quality Control Sample-Trip Blank          2006-08-14 2006     8  14
## 5      Quality Control Sample-Trip Blank          2006-08-14 2006     8  14
## 6      Quality Control Sample-Trip Blank          2006-08-14 2006     8  14
##   characteristic_name result_text       date
## 1        Arsenic mg/l           0 2006-08-14
## 2        Calcium mg/l           0 2006-08-14
## 3      Magnesium mg/l           0 2006-08-14
## 4        Arsenic mg/l           0 2006-08-14
## 5        Calcium mg/l           0 2006-08-14
## 6      Magnesium mg/l           0 2006-08-14

This is an incredibly rich data set. I have only kept the 20 most common quantitative measurements, but there are so many more. I have kept this data set in the long format, because there is very spotty measuring.

water_quality |> 
  group_by(characteristic_name) |> 
  summarize(n = n()) |> 
  arrange(desc(n))
## # A tibble: 20 × 2
##    characteristic_name                      n
##    <chr>                                <int>
##  1 Arsenic mg/l                           571
##  2 Calcium mg/l                           522
##  3 Magnesium mg/l                         522
##  4 Potassium mg/l                         485
##  5 Sodium mg/l                            485
##  6 Chloride mg/l                          280
##  7 Sulfur, sulfate (SO4) as SO4 mg/l      280
##  8 Phosphorus, orthophosphate as P mg/l   248
##  9 Temperature, water deg C               233
## 10 Specific conductance uS/cm             230
## 11 pH                                     226
## 12 Dissolved oxygen (DO) mg/l             216
## 13 Phosphorus as P mg/l                   210
## 14 Solids, Suspended (TSS) mg/l           209
## 15 Nitrogen, ammonia as N mg/l            208
## 16 Flow cfs                               203
## 17 Flow, severity (choice list)           198
## 18 Temperature, air deg C                 193
## 19 Turbidity FNU                          116
## 20 Turbidity NTU                           29
leaflet(data = elk) |> 
  addTiles() |> 
  addPolylines(~long, ~lat, color = "blue", weight = 2, opacity = 0.7) |> 
  addCircleMarkers(data = water_quality, ~longitude, ~latitude,
                   radius = 2, color = "red", fill = TRUE, fillOpacity = 0.5) |> 
  addLegend(position = "bottomright", colors = c("blue", "red"), labels = c("Elk Path", "Characteristic Locations"))

Exploring Water Quality Near Elk Movement

Of the many different locations the data set provides, there are six distinct locations surrounding Yellowstone National Park. I examined rivers and streams generally along the borders of the park and specifically at Snake River at Old Flagg Ranch 1000 Below Bridge and Snake River Below Site of New Visitor’s Center as these two locations are at the heart of elk movement.

From these locations, I explored water contents such as calcium, arsenic, sodium, sulfur, phosphorus, potassium, magnesium, nitrogen, chloride, dissolved oxygen, and pH. These data measures were plotted against each other by location site. Additionally, water temperature was measured and plotted.

It is important to examine data sets such as these when considering elk movement as these rivers and streams are their main water source. We can determine after discussing the elk movement and where they are frequently found, they are typically near major water sources and trek along these locations to guide their movement and sustain their journeys.

Scatterplot of Each Water Characteristic

Calcium

The first water content examined is calcium. Calcium is a mineral that keeps the body healthy by building strong bones and teeth, helping muscles move, helping nerves function, and helping blood vessels move blood. However, high levels of calcium can have an opposite effect such as causing poor muscle tone, poor kidney function, and abnormal heart rhythms.

In th case of elk, they need calcium to sustain their antlers, along with other minerals that will be discussed. Normal levels of calcium fall within the range of 8.5 and 10.2.

calcium = 
  water_quality |> 
  filter(characteristic_name == 'Calcium mg/l') |> 
  mutate(calcium = as.numeric(result_text)) 


plot_calcium = ggplot(calcium, aes(x = date, y = calcium, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Calcium Levels Over Time", 
    x = "Date", 
    y = "Calcium (mg/l)") +
  theme(legend.position = "right")

interactive_calcium = ggplotly(plot_calcium)

interactive_calcium

According to the plot, Madison River 1.21km West of MT/WY State Boundary and Madison River near West Yellowstone, MT contained consistent levels of calcium between 0 and 6.5-7 mg/l. This is slightly under the ideal range for calcium, but does not pose any health threats.

Additionally, the plot shows that Lamar River at USGS Gage near Ranger Station, Yellowstone River at Corwin Springs, Snake River Below Site of New Visitor’s Center, and Snake River at Old Flagg Ranch 1000 Below Bridge each reached high levels of calcium, above the ideal range. Lamar River at USGS reached the highest level of calcium mg/l across all locations on May 4, 2011 with a level of 35.8 mg/l.

The plot also suggests that generally in the colder months such as January and March, there was an increase in calcium levels and a decrease in the hotter months such as June and August across all locations.

Arsenic

Next up is arsenic. Arsenic is a naturally occurring, toxic, metalloid element. Arsenic is highly toxic and long-term exposure can cause cancer and skin lesions. Although arsenic is highly toxic, the Environmental Protection Agency (EPA) has set the standard at 0.010 mg/l.

arsenic = 
  water_quality |> 
  filter(characteristic_name == 'Arsenic mg/l') |> 
  mutate(arsenic = as.numeric(result_text)) 


plot_arsenic = ggplot(arsenic, aes(x = date, y = arsenic, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Arsenic Levels Over Time", 
    x = "Date", 
    y = "Arsenic (mg/l)") +
  theme(legend.position = "right")

interactive_arsenic = ggplotly(plot_arsenic)

interactive_arsenic

According to the plot, the Lamar River at USGS Gage near Ranger Station, the Yellowstone River at Corwin Springs, and Snake River Below Site of New Visitor’s Center each maintained a “safe” level of arsenic in their water sources. The highest arsenic levels from Snake River Below Site of New Visitor’s Center was on July 26, 2022 at 0.0370 mg/l. From the Lamar River at USGS near Ranger Station, the highest arsenic levels was 0.0103 mg/l and 0.0496 at the Yellowstone River at Corwin Springs.

Madison River 1.21km West of MT/WY State Boundary contained little arsenic level data, however, it reached a peak of 0.3000 mg/l on February 6, 2012 and did not drop below 0.1520 after July 11, 2011.

Snake River at Old Flagg Ranch 1000 Below Bridge generally maintained steady arsenic levels that did not increase above 0.05200. However, there was a very significant spike on August 24, 2010 in which arsenic levels rose to 0.4140, more than 3 tenths above the standard level.

Lastly, Madison River near West Yellowstone, MT has consistently reported significantly high levels of arsenic, the highest on February 26, 2017 at 0.3160 mg/l. Unlike calcium, there does not seem to be a significant correlation between time of year and arsenic levels.

Chloride

Next up is chloride. Chloride is an electrolyte commonly found in blood. It keeps the proper balance of body fluids and maintains the body’s acid-base balance. Consumption of chloride is typically not harmful, however, if chloride is found in water, that typically means contaminants such as bacteria, nitrates, or even lead may be found as well. It is important to note that high levels of chloride can indicate lead contamination as chlorine and lead must combine in order to create chloride. Although the data does not report lead levels, this would be an area of concern.

In the case of elk, chloride levels can be safe between 0-44 mg/l, however, levels above 133 are potentially harmful is consumed for long periods of time and can lead to death.

chloride = 
  water_quality |> 
  filter(characteristic_name == 'Chloride mg/l') |> 
  mutate(chloride = as.numeric(result_text))


plot_chloride = ggplot(chloride, aes(x = date, y = chloride, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Chloride Levels Over Time", 
    x = "Date", 
    y = "Chloride (mg/l)") +
  theme(legend.position = "right")

interactive_chloride = ggplotly(plot_chloride)

interactive_chloride

After taking a look at the plot, the water source with the lowest levels of chloride is the Lamar River at USGS Gage near Ranger Station, consistenly ranging from 0-4 mg/l. Additionally, Snake River Below Site of New Visitor’s Center also had relatively low levels steadly ranging from 0-6 mg/l and one spike to 14 mg/l on July 26, 2022.

Snake River at Old Flagg Ranch 1000 Below Bridge and the Yellowstone River at Corwin Springs had similar results in which chloride levels stayed roughly between 0-20 mg/l.

Between all locations, Madison River 1.21km West of MT/WY State Boundary and Madison River near West Yellowstone, MT had the highest levels of chloride ranging from 0-74.5 mg/l and 0-73 mg/l, respectively.

Dissolved Oxygen (DO)

Next up is dissolved oxygen. Dissolved oxygen refers to the amount of oxygen gas present water, or oxygen molecules that have been absorbed from the atmosphere and are free floating in water. This is often used as an indicator of water quality, as low levels can be detrimental to aquatic life and high levels are considered good for drinking, improving taste and supporting aquatic life.

For the elk, considering they receive their main drinking water from rivers surrounding Yellowstone National Park, a healthy range for dissolved oxygen is 6.5-8 mg/l.

It is typically seen that colder water will have high DO levels than water water, which means DO is usually higher in winter than summer.

dissolved_oxygen = 
  water_quality |> 
  filter(characteristic_name == 'Dissolved oxygen (DO) mg/l') |> 
  mutate(dissolved_oxygen = as.numeric(result_text)) 


plot_do = ggplot(dissolved_oxygen, aes(x = date, y = dissolved_oxygen, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Dissolved Oxygen Levels Over Time", 
    x = "Date", 
    y = "Dissolved Oxygen (DO) mg/l") +
  theme(legend.position = "right")

interactive_do = ggplotly(plot_do)

interactive_do

According to the plot, the Lamar River at USGS Gage near Ranger Station, Madison River 1.21km West of MT/WY State Boundary, Madison River near West Yellowstone, MT and Yellowstone River at Corwin Springs had similar levels of dissolved oxygen ranging between 6.5-14.6 mg/l. This is very close to the ideal range of dissolved oxygen mentioned previously. Additionally, the plot shows the dissolved oxygen levels increasing during winter months and decreasing during summer months, which is a commonly reported trend.

Aside from these four locations, Snake River at Old Flagg Ranch 1000 Below Bridge and Snake River Below Site of New Visitor’s Center had very similar trends, each ranging relatively between 1.220-13.170 mg/l and -0.020-12.410 mg/l, respectively. However, in the summer of 2009, each area reported a spike to 52.5 mg/l, followed by a sharp fall the next month.

To note, a negative dissolved oxygen reading indicates an issue with the device used to measure the water. Near-zero conditions can also produce negative readings, which means the device should be recalibrated or replaced entirely.

Magnesium

Next up is magnesium. Magnesium is a mineral that is essential for healthy muscles, nerves, bones and blood sugar levels. However, without consuming enough over time, there is a potential for health risks.

Healthy levels of magnesium are generally between 0.18-0.26 mg/l, and if taking large amount of magensium or more than 3.1 mg/l, this enters the unsafe range. This may cause effects such as blood pressure, slowed breathing, or even death.

magnesium = 
  water_quality |> 
  filter(characteristic_name == 'Magnesium mg/l') |> 
  mutate(magnesium = as.numeric(result_text)) 


plot_magnesium = ggplot(magnesium, aes(x = date, y = magnesium, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Magnesium Levels Over Time", 
    x = "Date", 
    y = "Magnesium (mg/l)") +
  theme(legend.position = "right")

interactive_magnesium = ggplotly(plot_magnesium)

interactive_magnesium

According to the plot, Madison River 1.21km West of MT/WY State Boundary and Madison River near West Yellowstone, MT had the lowest levels of magnesium across each of the locations. However, the levels did fluctuate over time. Specifically at Madison River 1.21km West of MT/WY State Boundary, the magnesium levels reached a high of 0.786 mg/l and consistently stayed around 0.7 mg/l. For Madison River near West Yellowstone, MT, the magnesium level reached a high of 1.0 mg/l in April, July, and October 2016, but the levels quickly decreased in November 2016 to 0 mg/l and stayed this way for the rest of the data.

Nitrogen

Nitrogen is an inert gas important for plant growth and a key additive in fertilizer. However, it is harmful as it can act like oxygen and lead to suffocation. There are safe levels, according to the EPA, at a maximum of 10 mg/l.

nitrogen = 
  water_quality |> 
  filter(characteristic_name == 'Nitrogen, ammonia as N mg/l') |> 
  mutate(nitrogen = as.numeric(result_text)) 


plot_nitrogen = ggplot(nitrogen, aes(x = date, y = nitrogen, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Nitrogen Levels Over Time", 
    x = "Date", 
    y = "Nitrogen (mg/l)") +
  theme(legend.position = "right")

interactive_nitrogen = ggplotly(plot_nitrogen)

interactive_nitrogen

According to the graph, Snake River at Old Flagg Ranch 1000 Below Bridge had 0 mg/l of nitrogen reported across all months and years. This most likely made it an ideal location for elk to migrate to and use as a main water source. Snake River Below Site of New Visitor’s Center and Madison River near West Yellowstone, MT had very similar readings with two significant spikes. Each location had a spike on May 15, 2017 at 0.05 mg/l. Snake River Below Site of New Visitor’s Center on February 26, 2017 at 0.03 mg/l on March 29, 2017 and Madison River near West Yellowstone, MT had a spike at 0.04 mg/l on February 26, 2017.

The highest levels of nitrogen across all locations was at Yellowstone River at Corwin Springs with readings as high as 0.3 mg/l. Otherwise, none of the locations had reading above 1 mg/l, which means it was safe in terms of nitrogen for the elk to drink.

Phosphorus

Phosphorus is an essential mineral and component of bones, teeth, and DNA. It is needed to create proteins and repairs cells and tissues. However, high levels of phosphorus causes body changes that pull calcium out of the bones, making them weak. It can also lead to dangerous calium deposits in blood vessels, lungs, eyes, and heart, leading to death over a long period of time.

Generally, phosphorus levels below 0.15 mg/l can lead to muscle weakness and impaired bone growth. High levels of phosphorus, also referred to as hyperphosphatemia, is at levels above 0.55 mg/l. A normal range is between 0.25 mg/l and 0.45 mg/l.

phosphorus = 
  water_quality |> 
  filter(characteristic_name == 'Phosphorus as P mg/l') |> 
  mutate(phosphorus = as.numeric(result_text)) 


plot_phosphorus = ggplot(phosphorus, aes(x = date, y = phosphorus, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Phosphorus Levels Over Time", 
    x = "Date", 
    y = "Phosphorus (mg/l)") +
  theme(legend.position = "right")

interactive_phosphorus = ggplotly(plot_phosphorus)

interactive_phosphorus

According to the graph, the water source in which majority of the elk were found had low levels of phosphorus, which is concerning in terms of muscle heatlh and bone growth. Only one of the two sites, Snake River Below Site of New Visitor’s Center, the elk were found in had two readings that fell into the normal range. One reading was on May 15, 2019 with a reading of 0.325 mg/l and the other reading was on May 18, 2023 with a reading of 0.36 mg/l.

In terms of the other four locations, two locations, the Lamar River at USGS Gage near Ranger Station and Yellowstone River at Corwin Springs had readings above the acceptable limit of 0.45 mg/l, on May 16, 2023 with 0.880 mg/l and June 16, 2022 with 1.14 mg/l, respectively.

Potassium

Potassium is a mineral and type of electrolyte the body needs to work properly. It helps nerves and heart function, as well as moves nutrients and waste around cells. However, high levels of potassium may be too much for the kidneys to balance, leading to heart damage and possibly death.

High levels of potassium are considered above 10.8 mg/l and a normal range is 6.48 to 9.36 mg/l. Low levels of potassium, also referred to as hypokalemia, can cause muscle weakness and fatigue.

potassium = 
  water_quality |> 
  filter(characteristic_name == 'Potassium mg/l') |> 
  mutate(potassium = as.numeric(result_text)) 


plot_potassium = ggplot(potassium, aes(x = date, y = potassium, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Potassium Levels Over Time", 
    x = "Date", 
    y = "Potassium (mg/l)") +
  theme(legend.position = "right")

interactive_potassium = ggplotly(plot_potassium)

interactive_potassium

According to the graph, Snake River at Old Flagg Ranch 1000 Below Bridge in which elk use as a water source and Snake River Below Site of New Visitor’s Center did not reach the minimum of the normal range, indicating that these main water sources could have resulted in insufficient levels of potassium for the elk. This could have caused hypokalemia and contributed to any slowdown in elk movement.

Sodium

Sodium is a mineral and electrolyte needed for normal muscle and nerve functions and maintaining blood pressure. If sodium is too low, also referred to as hyponatremia, this can cause loss of energy, confusion, or possibly death negatively impacting movement of elk. Sever hypernatremia, or high levels of sodium, can have similar effects, and therefore, it is important to stay within the normal range.

The normal range of sodium in water is below 20 mg/l, and higher than this can cause hypernatremia.

sodium = 
  water_quality |> 
  filter(characteristic_name == 'Sodium mg/l') |> 
  mutate(sodium = as.numeric(result_text)) 


plot_sodium = ggplot(sodium, aes(x = date, y = sodium, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Sodium Levels Over Time", 
    x = "Date", 
    y = "Sodium (mg/l)") +
  theme(legend.position = "right")

interactive_sodium = ggplotly(plot_sodium)

interactive_sodium

According to the graph, the Lamar River at USGS Gage near Ranger Station and Snake River Below Site of New Visitor’s Center had similar trends in which sodium levels stayed beneath 12 mg/l generally, with one exception on July 26, 2022 at the Snake River Below Site of New Visitor’s Center.

The other four locations had levels consistently above 20 mg/l, indicating exposure to these water could result in salt poisoning by high levels of sodium. This includes the Snake River at Old Flagg Ranch 1000 Below Bridge location most elk travel near that fluctuated between 0 and 45 mg/l.

It is important to note that data fluctuated in correlation with winter and summer months. This could indicate that in the winter when roads are more dangerous to drive on due to weather patterns and need to be salted, some of the runoff makes its way into these water sources.

Sulfur

Sulfur is a chemical element most reactive with other elements, including a few that have already been discussed. It is known to be of low toxicity and poses low risks, but meant to build and fix DNA and protect from cell damage. However, if animals consume too much sulfur, it may be toxic and can be fatal. Signs can include brain cell death and brain damage. “Harmful” levels are above 250 mg/l, but this only significantly affects taste and odor.

sulfur = 
  water_quality |> 
  filter(characteristic_name == 'Sulfur, sulfate (SO4) as SO4 mg/l') |> 
  mutate(sulfur = as.numeric(result_text))


plot_sulfur = ggplot(sulfur, aes(x = date, y = sulfur, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Sulfur Levels Over Time", 
    x = "Date", 
    y = "Sulfur (mg/l)") +
  theme(legend.position = "right")

interactive_sulfur = ggplotly(plot_sulfur)

interactive_sulfur

According to the graph, none of the locations reached above the harmful level of 250 mg/l, which means that elk were most likely not affected by the sulfur content in each location. It seems that each location also fluctuated based on time of the year, as it became hotter, sulfur increased and colder sulfur decreased.

Water pH

pH of water measures how acidic or how basic the water is on a scale from 0-14, in which 0 is highly acidic and 14 is highly basic. Ideal water pH is 7, which indicates pure or neutral water. Typically rain has a pH between 5.0 and 5.5, and acid rain has a pH around 4.0, ten times more acidic than normal rain.

The healthy level for pH of drinking water and what is commonly found in springs is between 6.5 and 8.5.

water_ph = 
  water_quality |> 
  filter(characteristic_name == 'pH') |> 
  mutate(water_ph = as.numeric(result_text)) 


plot_ph = ggplot(water_ph, aes(x = date, y = water_ph, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "pH Over Time", 
    x = "Date", 
    y = "pH") +
  theme(legend.position = "right")

interactive_ph = ggplotly(plot_ph)

interactive_ph

According to the plot, the pH in water was relatively similar, ranging in the normal level of 6.5 to 8.5 mg/l, at the Lamar River at USGS Gage near Ranger Station, Madison River 1.21km West of MT/WY State Boundary, Madison River near West Yellowstone, MT, and Yellowstone River at Corwin Springs. The highest between these four sites was from Yellowstone River at Corwin Spring at 9.380 mg/l. This is slightly more basic than the ideal range, but is not of significant concern. The lowest reading between the four sites was at the Lamar River at USGS Gage near Ranger Station at 6.1 mg/l, which is slightly more acidic than the normal range, but is also not of high concern.

Snake River at Old Flagg Ranch 1000 Below Bridge and Snake River Below Site of New Visitor’s Center, where the elk were primarly found, saw similar readings to that of the four other stations, however, there was one instance in each of the location that saw readings similar to acid rain. The first at Snake River at Olg Flagg Ranch 1000 Below Bridge, which on October 19, 2006 had a reading of 3.46 mg/l. At Snake River Below Site of New Visitor’s Center, the location had a reading of 5.57 mg/l on the same day.

Water Temperature

water_temp = 
  water_quality |> 
  filter(characteristic_name == 'Temperature, water deg C') |> 
  mutate(water_temp = as.numeric(result_text)) 


plot_water = ggplot(water_temp, aes(x = date, y = water_temp, color = location_id)) +
  geom_line(alpha = 0.6) +
  labs(
    title = "Water Temperature Levels Over Time", 
    x = "Date", 
    y = "Water Temperature deg C") +
  theme(legend.position = "right")

interactive_water = ggplotly(plot_water)

interactive_water

Water Quality Characteristics Over Time

location_data = water_quality |> 
  filter(characteristic_name %in% c("Arsenic mg/l", "Chloride mg/l", "Dissolved oxygen (DO) mg/l", "Magnesium mg/l", "Nitrogen, ammonia as N mg/l", "Phosphorus as P mg/l", "Potassium mg/l", "Sodium mg/l", "Sulfur, sulfate (SO4) as SO4 mg/l", "pH", "Temperature, water deg C")) |> 
  mutate(result_text = as.numeric(result_text))
plot_characteristics = ggplot(location_data, aes(x = date, y = result_text)) +
  geom_line(aes(color = location_id), size = 0.5) +
  facet_wrap(~ characteristic_name, scales = "free_y") +
  labs(
    title = "Water Quality Over Time",
    x = "Date",
    y = "Characteristic"
  )

interactive_char = ggplotly(plot_characteristics)

interactive_char