===== 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: ====
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
temp <- read.csv("Temperature.csv")
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()`).
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()`).
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()`).
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()`).
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()`).
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: ====
temp$decdate <- temp$Year + temp$dDay3 / 365
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()`).
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()`).
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()`).
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):")