Module07_Gordon

Author

Mason Gordon

#Module 07

Part 1

  • Use ggplot() to produce a histogram of salinity values
salinity <- ggplot(temp, aes(x = Salinity))
salinity + geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
Warning: Removed 798 rows containing non-finite outside the scale range
(`stat_bin()`).

  • Make a histogram of salinity values for each year of study, and then for each month
salinity + geom_histogram(color='lightblue', fill='white') + facet_wrap(~ Year)
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
Warning: Removed 798 rows containing non-finite outside the scale range
(`stat_bin()`).

salinity + geom_histogram(color='lightblue', fill='white') + facet_wrap(~ Month)
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
Warning: Removed 798 rows containing non-finite outside the scale range
(`stat_bin()`).

  • Make a boxplot of temperature values for each station
temp_plot <- ggplot(temp, aes(x = Temperature, y = Station))
temp_plot <- temp_plot + geom_boxplot()
temp_plot
Warning: Removed 927 rows containing non-finite outside the scale range
(`stat_boxplot()`).

  • Save the last figure to a png file
ggsave("TempByStation.png", temp_plot)
Saving 7 x 5 in image
Warning: Removed 927 rows containing non-finite outside the scale range
(`stat_boxplot()`).
  • Bonus: Reorganize the boxplot from low to high median temperatures
temp_plot <- ggplot(temp, aes(x = Temperature, y = reorder(Station, Temperature, median, na.rm = TRUE)))
temp_plot <- temp_plot + geom_boxplot()
temp_plot
Warning: Removed 927 rows containing non-finite outside the scale range
(`stat_boxplot()`).

Part 2

temp$decdate <- temp$Year + temp$dDay3 / 365
  • Now, using this variable make a scatterplot of temperature and salinity over time
Salinity <- ggplot(temp, aes(x = decdate, y = Salinity))
Temperature <- ggplot(temp, aes(x = decdate, y = Temperature))
Salinity + geom_point()
Warning: Removed 798 rows containing missing values or values outside the scale range
(`geom_point()`).

Temperature + geom_point()
Warning: Removed 927 rows containing missing values or values outside the scale range
(`geom_point()`).

  • Make a scatterplot of salinity, grouped using facet_wrap() into different ‘Areas’
Salinity + geom_point() + facet_wrap(~ Area)
Warning: Removed 798 rows containing missing values or values outside the scale range
(`geom_point()`).

  • Make a lineplot of salinity for each station, grouped into different ‘Areas’
Salinity + geom_line() + facet_wrap(~ Area)

  • Bonus: do the same but only for area ‘OS’
os <- subset(temp, Area == "OS")
os_plot <- ggplot(os, aes(x = decdate, y = Salinity))
os_plot + geom_line() + facet_wrap(~ Area)