library(ggplot2)
library(dplyr)
##
## 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
library(leaflet)
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(mapview)
library(lattice)
library(shiny)
library(sp)
library("readxl")
sheet1 <- read_excel("C:/Users/rcheb/Desktop/CoralReefData_Converted.xlsx")
sheet2<-read_excel("C:/Users/rcheb/Desktop/CoralReefData_Converted.xlsx", sheet = 2)
sheetONE <- sheet1
sheetONE$Genotype <- as.factor(sheetONE$Genotype)
sheetONE$Species <- as.factor(sheetONE$Species)
sheetONE
sheet1$LAT <- as.numeric(sheet1$LAT)
## Warning: NAs introduced by coercion
sheet1$LONG <- as.numeric(sheet1$LONG)
## Warning: NAs introduced by coercion
#remove duplicated data
reefnodup <- sheet1[!duplicated(sheet1$`Reef Site`), ]
reefnodup
###################################
#Filetering data for each location
###################################
#U47 Patch Reef
u47 <- select(filter(sheetONE, `Reef Site` == "U47 Patch Reef"),c(Species, Genotype, NumCorals))
#Carysfort Reef
caryreef <- select(filter(sheetONE, `Reef Site` == "Carysfort Reef"),c(Species, Genotype, NumCorals))
#Pickles Reef
pickle <- select(filter(sheetONE, `Reef Site` == "Pickles Reef"),c(Species, Genotype, NumCorals))
#Little Conch Ledge
little <- select(filter(sheetONE, `Reef Site` == "Little Conch Ledge"),c(Species, Genotype, NumCorals))
#Looe Key
looe <- select(filter(sheetONE, `Reef Site` == "Looe Key"),c(Species, Genotype, NumCorals))
#Molasses Reef
molasses <- select(filter(sheetONE, `Reef Site` == "Molasses Reef"),c(Species, Genotype, NumCorals))
#Grecian Rocks
grecian <- select(filter(sheetONE, `Reef Site` == "Grecian Rocks"),c(Species, Genotype, NumCorals))
#White Banks
white <- select(filter(sheetONE, `Reef Site` == "White Banks"),c(Species, Genotype, NumCorals))
#Western Sambo
western <- select(filter(sheetONE, `Reef Site` == "Western Sambo"),c(Species, Genotype, NumCorals))
#Marker 32
marker32 <- select(filter(sheetONE, `Reef Site` == "Marker 32"),c(Species, Genotype, NumCorals))
#U19 Patch
u19 <- select(filter(sheetONE, `Reef Site` == "U19 Patch"),c(Species, Genotype, NumCorals))
#American Shoal
shoal <- select(filter(sheetONE, `Reef Site` == "American Shoal"),c(Species, Genotype, NumCorals))
#Coffins Patch
coffin <- select(filter(sheetONE, `Reef Site` == "Coffins Patch"),c(Species, Genotype, NumCorals))
#North Dry Rocks
north <- select(filter(sheetONE, `Reef Site` == "North Dry Rocks"),c(Species, Genotype, NumCorals))
#Sombrero Reef
sombrero <- select(filter(sheetONE, `Reef Site` == "Sombrero Reef"),c(Species, Genotype, NumCorals))
###################################
#Creating plots for each location
###################################
#u47 Patch Reef Plot
u47plot <- ggplot(data = na.omit(u47), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "U47 Patch Reef", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Carysfort Plot
caryplot <- ggplot(data = na.omit(caryreef), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Carysfort Reef", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Pickles Reef Plot
pickleplot <- ggplot(data = na.omit(pickle), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Pickles Reef", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Little Conch Ledge Plot
littleplot <- ggplot(data = na.omit(little), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Little Conch Ledge", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Looe Key Plot
looeplot <- ggplot(data = na.omit(looe), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Looe Key", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Molasses Reef Plot
molassesplot <- ggplot(data = na.omit(molasses), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Molasses Reef", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Grecian Rocks Plot
grecianplot <- ggplot(data = na.omit(grecian), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Molasses Reef", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#White Banks Plot
whiteplot <- ggplot(data = na.omit(white), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "White Banks", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Western Sambo Plot
westernplot <- ggplot(data = na.omit(western), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Western Sambo", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Marker 32 Plot
markerplot <- ggplot(data = na.omit(marker32), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Marker 32", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#U19 Patch Plot
u19plot <- ggplot(data = na.omit(u19), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "U19 Patch", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#American Shoal Plot
shoalplot <- ggplot(data = na.omit(shoal), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "American Shoal", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Coffins Patch Plot
coffinplot <- ggplot(data = na.omit(coffin), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Coffins Patch", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#North Dry Rocks Plot
northplot <- ggplot(data = na.omit(coffin), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "North Dry Rocks", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
#Sombrero Reef Plot
sombreroplot <- ggplot(data = na.omit(sombrero), aes(x= Species, y= NumCorals, fill= Genotype)) +
geom_bar(stat="identity") +
guides(fill=FALSE) +
labs(title = "Sombrero Reef", subtitle = "Colors represent genotype diversity", y = "Number of Corals Planted")+
ylim(0,3500)
###################################
#Creating the Map
###################################
map<- leaflet() %>%
addTiles() %>%
clearBounds() %>%
addMouseCoordinates()%>%
addMarkers(lng= -80.4422, lat= 24.994517, popup= popupGraph(u47plot),label ="U47 Patch Reef")%>%
addMarkers(lng= -80.209917, lat= 25.221233, popup= popupGraph(caryplot), label ="Caryfort Reef") %>%
addMarkers(lng= -80.4157, lat= 24.984333, popup= popupGraph(pickleplot),label ="Pickles Reef")%>%
addMarkers(lng= -80.474433, lat= 24.942517, popup=popupGraph(littleplot),label ="Little Conch Ledge")%>%
addMarkers(lng= -81.40375, lat= 24.546533, popup= popupGraph(looeplot),label ="Looe Key")%>%
addMarkers(lng= -80.3766, lat= 25.008783, popup= popupGraph(molassesplot),label ="Molasses Reef")%>%
addMarkers(lng= -80.3037, lat= 25.110567, popup= popupGraph(grecianplot),label ="Grecian Rocks")%>%
addMarkers(lng= -80.37285, lat= 25.0393, popup= popupGraph(whiteplot),label ="White Banks")%>%
addMarkers(lng= -81.71325, lat= 24.480433, popup=popupGraph(westernplot),label ="Western Sambo")%>%
addMarkers(lng= -81.7434, lat= 24.474117, popup= popupGraph(markerplot),label ="Marker 32")%>%
addMarkers(lng= -80.4679, lat= 24.987833, popup= popupGraph(u19plot),label ="U19 Patch")%>%
addMarkers(lng= -81.52035, lat= 24.685567, popup= popupGraph(shoalplot),label ="American Shoal")%>%
addMarkers(lng= -80.964183, lat= 24.9822000, popup=popupGraph(coffinplot),label ="Coffins Patch")%>%
addMarkers(lng= -80.29425, lat= 25.130583, popup= popupGraph(northplot),label ="North Dry Rocks")%>%
addMarkers(lng= -81.10996, lat= 24.6267, popup= popupGraph(sombreroplot),label ="Sombrero Reef")
map