Interactive Data Visualization

Row

Data Source:EDDMapS. 2020. Early Detection & Distribution Mapping System. The University of Georgia - Center for Invasive Species and Ecosystem Health. Available online at http://www.eddmaps.org/; last accessed May 10, 2020."

Invasive Reptile Trends

Total Records in Florida

10108

Latitudinal HotSpots

North Florida

126

Central Florida

838

South Florida

9144

Row

Species by County

HotSpot Counties

Row

Invasive Reptile Records Per Year

Maps

Row

HotSpot Map

Species Observations

Data Table

Species/Month

Pivot Table: Monthly Activity per Species

Monthly Activity/County

Pivot Table: Monthly Activity per County

About

This Flex Dashboard was created by Russell J Gray. Source code is open-source and available under the “</>Source Code” tab (top right)

For any questions comments or inquiries, please contact the author at

Data Source: EDDMapS. 2020. Early Detection & Distribution Mapping System. The University of Georgia - Center for Invasive Species and Ecosystem Health. Available online at http://www.eddmaps.org/; last accessed May 10, 2020."

---
title: "Invasive Reptiles in Florida"
output: 
  flexdashboard::flex_dashboard:
    theme: journal
    orientation: rows
    vertical_layout: fill
    social: ["twitter","facebook", "menu"]
    source_code: embed
   
---


```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
library(DT)
library(rpivotTable)
library(ggplot2)
library(plotly)
library(dplyr)
library(openintro)
library(highcharter)
library(RColorBrewer)
library(ggvis)
library(googleVis)
library(lubridate)
library(data.table)
library(sp)
library(maptools)
library(ggplot2)
library(plyr)
library(tidyverse)
library(urbnmapr)
library(maps)
library(usmap)
library(cdlTools)
library(mapview)
library(googleVis)
```


```{r}
data = read.csv("C:/Users/Russe/Desktop/Helping with R/flex dashboard/repflexdat.csv")
data = na.omit(data)

```


```{r}

nb.cols <- 11
mycolors <- colorRampPalette(brewer.pal(8, "Reds"))(nb.cols)

```


Interactive Data Visualization{data-navmenu="Project Sections"}
==============================
Row
------------------------------

### Data Source:EDDMapS. 2020. Early Detection & Distribution Mapping System. The University of Georgia - Center for Invasive Species and Ecosystem Health. Available online at http://www.eddmaps.org/; last accessed May 10, 2020."

```{r}
valueBox(paste("Invasive Reptile Trends"),
color = "danger")

```

### Total Records in Florida

```{r}
valueBox(length(data$ComName),
icon = "fas fa-chart-bar")

```


### **Latitudinal HotSpots**

```{r}
gauge(round(mean(data$Latitude),
            digits = 2),
            min = min(data$Latitude),
            max = max(data$Latitude),
            sectors = gaugeSectors(success = c(29.6,30.9),
                          warning = c(26.9, 29.6),
                          danger = c(24.32054, 26.9),
                          colors = c('green','yellow','red')))
                          
                          
```


### North Florida
```{r}
valueBox(sum(data$region == "North"),
icon = "fas fa-chart-line ")

```

### Central Florida
```{r}
valueBox(sum(data$region == "Central"),
icon = "fas fa-chart-line")

```

### South Florida
```{r}
valueBox(sum(data$region == "South"),
icon = "fas fa-chart-line")

```


Row
-----------------------------------------

### Species by County

```{r}
p1 <- data %>%
  dplyr::group_by(Location) %>%
  dplyr::summarise(SciName = n()) %>%
  plot_ly(x = ~Location,
         y = ~SciName,
         type = 'bar') %>%
  layout(xaxis = list(title = "Invasive Reptiles per County"),
         yaxis = list(title = "Count"))
p1
```


### HotSpot Counties
```{r}

 piedat <- data %>%
  dplyr::group_by(Location) %>%
  dplyr::summarise(SciName = n()) %>%
  filter(SciName > 50)

nb.cols <- 11
gradient <- colorRampPalette(brewer.pal(8, "Spectral"))(nb.cols)
piedat <- piedat %>% arrange(desc(SciName))
piedat$colors <- gradient


p2 <- plot_ly(piedat, labels = ~Location, values = ~SciName,
              marker = list(colors = ~colors)) %>%
  add_pie(hole = 0.5) %>%
  layout(xaxis = list(zeroline = F,
                           showline = F,
                           showticklabels = F,
                           showgrid = F),
                      yaxis = list(zeroline = F,
                                   showline = F,
                                   showticklabels = F,
                                   showgrid = F))
p2

```

Row
-------------------------------------------------

### Invasive Reptile Records Per Year
```{r}

p4 <- data %>%
  dplyr::group_by(year) %>%
  dplyr::summarise(SciName = n()) %>%
  plot_ly(x = ~year,
         y = ~SciName,
         type = 'bar',
         name = "Records") %>%
   add_lines(y = ~fitted(loess(SciName ~ year)),
            name = "Trend",
            color = I("#FFC125"),
            showlegend = T,
            line = list(width = 5))%>%
  layout(xaxis = list(title = "Records per year"),
         yaxis = list(title = "'Count"))
  
p4

```



Maps{data-navmenu="Project Sections"}
========================================

Row
----------------------------------------

### HotSpot Map 
```{r}
require(ggplot2)

fldata <- data %>%
  dplyr::group_by(Location) %>%
  dplyr::summarise(SciName = n())

fldata$Location <- as.character(fldata$Location)
fldata$county <- tolower(fldata$Location)
#add FIPScode
fldata$county_fips <- usmap::fips("Florida", county = fldata$county)

# get shapefile
states <- map_data("state")

florida <- subset(states, region %in% c("florida"))

#convert to df
fl_df <- subset(states, region == "florida")

counties <- map_data("county")
fl_county <- subset(counties, region == "florida")

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

fl_county_map <- fl_base + theme_minimal() + 
  geom_polygon(data = fl_county, fill = NA, color = "white") +
  geom_polygon(color = "black", fill = NA)

# add fldata
fldata$county <-tolower(fldata$county)
fldata_tab <- dplyr::select(fldata, county, SciName, county_fips)
#change colname
colnames(fldata_tab) <- c("subregion", "total", "county_fips")

# combine fldata
fl_combined_counties <- inner_join(fldata_tab, fl_county, by = "subregion")

# drop axes and ticks
elements <- theme(
  axis.text = element_blank(),
  axis.line = element_blank(),
  axis.ticks = element_blank(),
  panel.border = element_blank(),
  panel.grid = element_blank(),
  axis.title = element_blank(),
  panel.background = element_blank()
)

# make a descriptive column
fl_combined_counties$observations <- cut(fl_combined_counties$total,breaks=c(0, 5, 10, 20, 40, 60, 80, 100, 1000, Inf),labels = c("0-5","50-10","10-20","20-40","40-60",                                                           "60-80","80-100","100-1000","1000+"))


flmap <- fl_base + 
  geom_polygon(data = fl_county, fill = "white", color = "black")+
  geom_polygon(color = "black", fill = NA) +
  geom_polygon(data = fl_combined_counties, aes(fill = observations), color = "black") +
  scale_color_manual(values = "#DA1616",
                     labels = "Observations") +
 scale_fill_brewer(palette = "Reds") +
  theme(legend.position = "bottom") +
  guides(fill = guide_legend(nrow=1, override.aes = list(alpha = 1), 
                             label.position="bottom",
                             label.hjust = .5)) +
  theme_minimal()+
  labs(fill="", color="")+
  theme(legend.position="none",
        legend.key.width = unit(1, "cm"), 
        legend.key.height = unit(0.5, "cm"),
        legend.key = element_blank(),
        legend.text = element_text(size=11))

# store the ggplotly object
ggplotly(flmap)


```


### Species Observations
```{r}

sp <- SpatialPoints(cbind(data$Longitude, data$Latitude),
                    proj4string = CRS("+init=epsg:4326"))

sp$Species <- data$SciName


mapview(sp, legend=FALSE)

```



Data Table{data-navmenu="Project Sections"}
=======================================================

```{r}

datatable(data,
          caption = "Invasive Reptile Data",
          rownames = T,
          filter = "top",
          options = list(pageLength = 25))

```



Species/Month{data-navmenu="Project Sections"}
========================================================

### Pivot Table: Monthly Activity per Species
```{r}

data$month <- factor(data$month, levels = month.name)

rpivotTable(data,
            aggregatorName = "Count",
            cols = "month",
            rows = "SciName",
            rendererName = "Heatmap")

```



Monthly Activity/County{data-navmenu="Project Sections"}
========================================================

### Pivot Table: Monthly Activity per County
```{r}

data$month <- factor(data$month, levels = month.name)

rpivotTable(data,
            aggregatorName = "Count",
            cols = "month",
            rows = "Location",
            rendererName = "Heatmap")

```

About{data-navmenu="Project Sections"}
========================================================

This Flex Dashboard was created by Russell J Gray.
Source code is open-source and available under the "</>Source Code" tab (top right)

For any questions comments or inquiries, please contact the author at rgrayherpetology@gmail.com

Data Source: EDDMapS. 2020. Early Detection & Distribution Mapping System. The University of Georgia - Center for Invasive Species and Ecosystem Health. Available online at http://www.eddmaps.org/; last accessed May 10, 2020."