===== The dataset Temperature.csv, a file with sea temperature and salinity recorded from 31 stations over 15 years. The stations are located in one of 10 areas.There are two parts to this exercise. =====

==== Part 1: ====

- Load required packages:
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
- Load the dataset:
temp <- read.csv("Temperature.csv")
- Histogram of Salinity Values:
ggplot(data = temp, aes(x = Salinity)) +
  geom_histogram() +
  labs(x = "Salinity", y = "Count", title = "Histogram of Salinity Values")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 798 rows containing non-finite values (`stat_bin()`).

- Histogram of Salinity Values for Each Year:
ggplot(data = temp, aes(x = Salinity)) +
  geom_histogram() + facet_wrap(~ Year) +
  labs(x = "Salinity", y = "Count", title = "Histogram of Salinity Values by Year")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 798 rows containing non-finite values (`stat_bin()`).

- Histogram of Salinity Values for Each Month:
ggplot(data = temp, aes(x = Salinity)) +
  geom_histogram() + facet_wrap(~ Month) +
  labs(x = "Salinity", y = "Count", title = "Histogram of Salinity Values by Month")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 798 rows containing non-finite values (`stat_bin()`).

- Boxplot of Temperature Values for Each Station:
ggplot(data = temp, aes(x = Station, y = Temperature)) +
  geom_boxplot() + 
  labs(x = "Station", y = "Temperature", title = "Boxplot of Temperature Values by Station")
## Warning: Removed 927 rows containing non-finite values (`stat_boxplot()`).

- Save the last figure to a PNG file:
ggsave("boxplot_temperature.png", plot = last_plot(), device = "png")
## Saving 7 x 5 in image
## Warning: Removed 927 rows containing non-finite values (`stat_boxplot()`).
- Bonus: Reorganize the Boxplot from Low to High Median Temperatures:
temp <- temp %>%
  mutate(Station = factor(Station, levels = unique(Station)[order(tapply(Temperature, Station, median))]))

ggplot(data = temp, aes(x = Station, y = Temperature)) +
  geom_boxplot() +
  labs(x = "Station", y = "Temperature", title = "Boxplot of Temperature Values by Station (Reordered)")
## Warning: Removed 927 rows containing non-finite values (`stat_boxplot()`).

==== Part 2: ====

- Add decimal date as a variable:
temp$decdate <- temp$Year + temp$dDay3 / 365
- Scatterplot of Temperature and Salinity Over Time:
ggplot(data = temp, aes(x = decdate, y = Temperature)) +
  geom_point(aes(color = Salinity)) +
  labs(x = "Decimal Date", y = "Temperature", title = "Temperature & Salinity Over Time:")
## Warning: Removed 927 rows containing missing values (`geom_point()`).

- Scatterplot of Salinity, Grouped by ‘Areas’:
ggplot(data = temp, aes(x = decdate, y = Salinity)) +
  geom_point() + facet_wrap(~ Area) +
  labs(x = "Decimal Date", y = "Salinity", title = "Salinity Over Time (Grouped by Areas):")
## Warning: Removed 798 rows containing missing values (`geom_point()`).

- Lineplot of Salinity for Each Station, Grouped by ‘Areas’:
ggplot(data = temp, aes(x = decdate, y = Salinity, color = Station)) +
  geom_line() + facet_wrap(~ Area) +
  labs(x = "Decimal Date", y = "Salinity", title = "Salinity Over Time (Grouped by Areas & Stations):")
## Warning: Removed 4 rows containing missing values (`geom_line()`).

- Bonus: Lineplot of Salinity for Each Station, Grouped by ‘Areas’ for Only ‘OS’ area:
ggplot(data = subset(temp, Area == "OS"), aes(x = decdate, y = Salinity, color = Station)) +
  geom_line() +
  labs(x = "Decimal Date", y = "Salinity", title = "Salinity Over Time (Area: OS):")

** End of Script ****