Click through the tabs to explore the results. The interactive plot is at the “Species distribution plot” tab

Setup

I plotted the data using the leaflet package and used the Janitor, DT, and Tidyverse tools for data wrangling

library(leaflet)
library(tidyverse)
library(DT)
library(janitor)

Introduction

This map shows the distribution of two jellyfish species in the South-West Atlantic Ocean. I created this plot using the information from the PloSone journal publication “Macroscale abundance patterns of hydromedusae in the temperate Southwestern Atlantic (27°–56° S)”. The article can be found at https://doi.org/10.1371/journal.pone.0217628, and the data is at the SEANOE website: https://www.seanoe.org/data/00501/61229/. As a co-author of the paper, I made all of the paper’s analysis and maps. This time, I used the information to create the interactive plot required for the second week’s assignment of the Developing Data Products course from Johns Hopkins University.

Get the data

url = "https://www.seanoe.org/data/00501/61229/data/64809.csv"

df <- read_csv2(url, locale = locale(decimal_mark = ',')) %>%
  janitor::clean_names() %>% 
  mutate_all(~replace(., . == -9999, NA)) %>% 
  mutate(year = as.Date(as.character(year), format = "%Y"))

df %>% 
  datatable(filter = "top",
            extensions = c('Buttons','FixedColumns', 'ColReorder'),
            options = list(dom = 'Bfrtip',
                           autoWidth = TRUE,
                           colReorder = TRUE,
                           scrollX = TRUE,
                           fixedColumns = TRUE, 
                           searchHighlight = TRUE)
  ) 

Species distribution plot

# Create a palette that maps factor levels to colors
pal <- colorFactor(c("navy", "red"), domain = c("liriope_tetraphylla", "obelia_sp"))

df %>%
  mutate(id = row.names(.)) %>%
  relocate(id, .before = year) %>% 
  select(id, year, latitude, longitude, liriope_tetraphylla, obelia_sp) %>% 
  pivot_longer(cols = c(liriope_tetraphylla, obelia_sp),
               names_to = 'species', values_to = 'abundance') %>%
  
  # get values higher than 0
  filter(abundance > 0) %>%
  mutate(species = as.factor(species)) %>%
  
  # keep just unique rows
  distinct() %>%

  leaflet() %>% 
  addTiles() %>% 
  addCircleMarkers(lng = ~longitude, lat = ~latitude,
                   radius = ~ (abundance *.005),
                   color = ~pal(species),
                   stroke = FALSE, fillOpacity = 0.5,
                   popup = ~paste("abundance: ", as.character(abundance))) %>% 
  addLegend(labels = c('L. tetraphylla', 'Obelia sp.'), colors = c('navy', 'red'))