'Mapping Multiple Species Ranges using Alpha hulls

I am trying to plot various species' ranges using alpha/concave hulls to create a map with a filled-in shape that represents that species range in the United States.

I have tried to do this multiple ways using packages like alphahull and concaveman. I like the shape of the alpha hull that the package 'alphahull' returns the best out of the packages, but there seems to be no way to fill in the resulting hull shape on a map. I am a beginner at R and have tried to follow a few tutorials on how to convert the hull it returns into a polygon, but with no luck.

Does anyone know a way to manipulate the functions in r package alphahull to create a filled in polygon shape on a ggmap?

Here is my current attempt with made-up data points:

library(alphahull)
library(plyr)
library(tidyverse)
library(tidyr)
library(ggplot2)
library(ggmap)
library(sp)

Loading in species occurrence data and creating basemap of us:

df <- data.frame(species = rep("sp1",15),
                 decimalLongitude =(c(-73.3, -88.0, -68.3, -69.8, -87.1, -68.6, -87.1, -68.5, -68.7, -90.3, -69.4, -87.5, -67.4, -67.7, -68.3)),
                  decimalLatitude =(c(42.0, 45.4, 46.0, 44.3, 45.1, 45.2, 45.1, 45.4, 45.7, 39.0, 44.1, 44.5, 45.2, 45.4, 47.2)))


us <- get_stamenmap(bbox = c(left = -125.0011, bottom = 22.9493, 
                             right = -66.9326, top = 51), 
                    zoom = 4)
ggmap(us)

I've tried different ways to add the alpha hull to the basemap using various functions in alphahull, this is the way to add it as a layer, but the package does not recognize any aesthetics I would normally use to fill in the hull:

ggmap(us) +
  ahull_track(df$decimalLongitude, df$decimalLatitude, alpha = 10, nps = 300) +
  geom_point(data = df, aes(df$decimalLongitude, df$decimalLatitude))+
    labs(title = 'Sphinx canadensis (Boisdulval, 1875)')

This results in this map, and it's perfect other than I need to fill in the shape representing the range: Sphinx canadensis range in US

I've also seen a few tutorials converting the object returned by the function 'ashape' from the package 'alphahull' into a polygon and then adding it to a ggmap, but those were super complex and didn't work when I tried. I feel like it should be an easy fix to my original code, but I've been messing with different methods for days now to no avail.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source