-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathteresa_test_plots.Rmd
153 lines (110 loc) · 3.75 KB
/
teresa_test_plots.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
title: "teresa_test_plot"
author: "Teresa Gonzalez"
date: "1/26/2022"
output: html_document
---
###Set up
####Load Libraries
```{r}
#read in data
library(readr)
#plotting
library(ggplot2)
library(tidyverse)
#arranging plots in panel
library(ggpubr)
#creating interactive maps in R
library(leaflet)
#splitting and averaging by unique values
library(data.table)
```
####Read in Files
```{r}
#cast and bottle preprocessed data
cast_bottle <- read_csv("data/preprocessed/bottle_and_cast.csv")
#descriptions of the variables in the cast and bottle preprocessed data
descrip <- read_csv("data/Bottle Field Descriptions (1).csv")
```
```{r}
#creating a new dataframe from the cast_bottle preprocessed data
sal_tem_o2 <- cast_bottle %>%
#selecting only temp, salinity, oxygen, depth, bottle id, cast id, year for new dataframe
select(T_degC, Salnty, O2ml_L, Depthm, Btl_Cnt, Cast_ID, Year) %>%
#making a longer dataframe and putting temp, salinity, oxygen into a column called variable
#and the values into a column called values
pivot_longer(1:3, names_to = "Variable", values_to = "Value")
```
###Creating Graphs
####Graph of Salinity, Temperature, and Oxygen vs Depth
```{r}
#creating a plot from the new dataframe with the salinity, temp, oxygen -> variable column
sal_tem_o2_vs_depth <- ggplot(data = sal_tem_o2, aes(x = Value, y = Depthm)) +
#putting everything into one graph and color coding by what type of variable
geom_point(aes(color = Variable)) +
scale_color_manual(values = c("darkred", "steelblue", "darkgreen")) +
#reversing the y-axis so it resembles a thermocline graph
scale_y_reverse()
sal_tem_o2_vs_depth
# panel of graphs instead of all on same/ diff scales?
#time and space?
```
Temperature and O2 both decrease with depth.
####Graph of salinity, temp, oxygen panels
```{r}
#salinity plot
salinity_plot <- ggplot() +
#putting everything into one graph and color coding by what type of variable
geom_line(data = cast_bottle, aes(x = Salnty, y = Depthm)) +
scale_y_reverse()
salinity_plot
#temperature plot
temp_plot <- ggplot() +
#putting everything into one graph and color coding by what type of variable
geom_line(data = cast_bottle, aes(x = T_degC, y = Depthm)) +
scale_y_reverse()
temp_plot
#oxygen plot
o2_plot <- ggplot() +
#putting everything into one graph and color coding by what type of variable
geom_line(data = cast_bottle, aes(x = O2ml_L, y = Depthm)) +
scale_y_reverse()
o2_plot
#panel of graphs
sal_temp_o2_grid <- ggarrange(salinity_plot, temp_plot, o2_plot,
ncol = 3)
```
####Graph of Year vs Oxygen
```{r}
#multiple sampling in a year, first make an ave, (use day, month, hour), use just one depth, or location
year_o2_plot <- ggplot(data = cast_bottle, aes(x = Year, y = O2ml_L, group = )) +
geom_line() +
scale_color_manual(values = c("darkred", "steelblue", "darkgreen"))
year_o2_plot
```
Oxygen not decreasing with time?
####Graph of pH vs Depth
```{r}
#all Na's for depth with this current data, not much to do with pH right now
ph1_vs_depth <- ggplot(data = cast_bottle, aes(x = pH1, y = Depthm)) +
geom_line()
ph1_vs_depth
```
####Looking into map making in R
```{r}
#take the averages of the lat/long for each station
station_avg <- setDT(cast_bottle)[, .(mean_lat = mean(Lat_Dec), mean_long = mean(Lon_Dec)), by = Sta_ID]
#create a base map using leaflet
basemap <- leaflet() %>%
#set the latitude and longitude for California, zoom into desired area
setView(lng = -119.4179, lat = 36.7783, zoom = 5.3) %>%
#add markers for each of the stations average lat and long
addTiles() %>%
addCircleMarkers(
lat = station_avg$mean_lat,
lng = station_avg$mean_long,
label = station_avg$Sta_ID,
color = "red",
radius = 0.6)
basemap
```