---
title: "Mapping Retrieval Sites"
author: "Chris"
date: "2/14/2023"
output:
  pdf_document: default
  html_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Install anything missing & call the libraries we start with


```{r }

install.packages("mapdata")
library(ggplot2, ggmap, maps, "mapdata")

```
Testing the code from the website: https://eriqande.github.io/rep-res-web/lectures/making-maps-with-R.html

Going to start with direct cut & paste from site to replicate what I see. It works if you run the code without assigning it to object 'gg1'

```{r cars}
usa <- map_data("usa")
gg1 <-ggplot() + geom_polygon(data = usa, aes(x=long, y = lat, group = group)) + 
  coord_fixed(1.3)


```
Code to add points, here as a placeholder for me to add my own points after I know it can work


```{r, echo=FALSE}

labs <- data.frame(
  long = c(-122.064873, -122.306417),
  lat = c(36.951968, 47.644855),
  names = c("SWFSC-FED", "NWFSC"),
  stringsAsFactors = FALSE
  )  

gg1 + 
  geom_point(data = labs, aes(x = long, y = lat), color = "black", size = 5) +
  geom_point(data = labs, aes(x = long, y = lat), color = "yellow", size = 4)





```
Let's grab state data
```{r}
states <- map_data("state")
dim(states)
head(states)
```
Going to map the west coast
```{r}
west_coast <- subset(states, region %in% c("california", "oregon", "washington"))

ggplot(data = west_coast) + 
  geom_polygon(aes(x = long, y = lat, group = group), fill = "palegreen", color = "black") + 
  coord_fixed(1.3)
```
mapping WA
```{r}
library("cowplot")

wa_df <- subset(states, region== "washington")
head(wa_df)

counties <- map_data("county")
wa_county <- subset(counties, region== "washington")
head(wa_county)

wa_base <- ggplot(data = wa_df, mapping = aes(x = long, y = lat, group = group)) + 
  coord_fixed(1.3) + 
  geom_polygon(color = "black", fill = "gray")
wa_base + theme_nothing()

wac <- wa_base + theme_nothing() + 
  geom_polygon(data = wa_county, fill = NA, color = "white") +
  geom_polygon(color = "black", fill = NA)  # get the state border back on top

```
Now to plot the PS region
```{r}
wac + coord_fixed(xlim = c(-124, -122),  ylim = c(46, 49), ratio = 1.3)

```
Adding the retrieval points
```{r}
location<- read.csv("mussel.csv")
head(location)

# create plotting df
# gotta add site names
latitude <- location[,5]
longitude <- location[,6]
cage <- data.frame(longitude, latitude)

wac + 
  geom_point(data = cage, aes(x = "Longitude", y = "Latitude"), color = "black", size = 5) +
  geom_point(data = cage, aes(x = "longitude", y = "Latitude"), color = "yellow", size = 4)

```
```{r, echo=FALSE}

```




Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
