R/eq_map.R

#' A interactive map showing earthquakes with custom annotations.
#'
#' This function is used to plot EQ data on map with radius of circle based on the primary magnitude.
#' Currently this is limited to the magnitude by code because that is what the assignment said to do.
#'
#' @param data A \code{data.frame} output from \code{eq_clean_data} or substantially similar
#' data. This is required as the radius of points and the latitude and longitude are mapped to
#' columns named "EQ_PRIMARY", "LATITUDE", "LONGITUDE" (respectively). These are defaults from
#' \code{eq_clean_data}, so when not using this function you must rename data appropriately.
#'
#' @param annot_col Column inside \code{data} that will be used to annotate the data
#'
#' @importFrom leaflet leaflet addProviderTiles addCircleMarkers
#'
#' @export
#'
#' @examples
#' \dontrun{
#'
#' EQdata %>%
#'       mutate(maplabel=eq_create_label(.)) %>%
#'       eq_map(annot_col=maplabel)
#'
#' }
#'
eq_map <- function(data, annot_col)
{

  leaflet::leaflet() %>%
    leaflet::addTiles() %>%
    leaflet::addCircleMarkers(data = data,
                              radius = ~EQ_PRIMARY,
                              lng = ~LONGITUDE,
                              lat = ~LATITUDE,
                              popup = ~data[[`annot_col`]])

}
JJNewkirk/NOAAEQ documentation built on May 27, 2019, 1:12 p.m.