R/Map_Function.R

Defines functions YearColorMap

Documented in YearColorMap

#' Generates a color-blind friendly map based on locations from a dataframe generated by Pull__Cort
#' 
#' Generates a map of taxa based on locations provided by a dataframe generated by the Pull__Cort function. Plot points are colored according the phrase used to search for taxa in the origional function, and labels are based on the year recorded and scientific name.
#'  
#' @param df A dataframe generated by Pull_Cort you'd like to map
#' @return Outputs a map colored according to searched taxa and labeled according to scientific name.
#' @export YearColorMap

YearColorMap <- function(df){
  tot_merged <- unite(df, year_and_name, year, acceptedScientificName)
  levs <- factor(df$column_label)
  Mapss <- mutate(df, year_and_name = tot_merged$year_and_name)
  factpal <- colorFactor( palette = magma(length(levs)
  ), levs)
  Mapss %>% 
    group_by(scientificName) %>% 
    leaflet() %>%
    addTiles() %>% 
    addCircleMarkers(
      ~decimalLongitude, 
      ~decimalLatitude,
      color = ~factpal(column_label),
      stroke = FALSE, fillOpacity = 0.5, label = Mapss$year_and_name
    ) %>% addLegend(position = "bottomright", pal = factpal, values = ~column_label, title = "Taxa")}

#This function requires leaflet, dplyr, viridis, and tidyr libraries
W0650629/Project-3 documentation built on Dec. 2, 2019, 4:51 p.m.