##' @import leaflet
##' @importFrom lubridate year is.Date
NULL
#' This creates the label for the points on the interative map
#'
#' @param data the raw dataset
#' @return a column of html text
#' @example eq_create_label(noaa)
#' @export
eq_create_label <- function(data) {
paste(ifelse(is.na(data$LOCATION_NAME),"", paste("<b>Location: </b>",
data$LOCATION_NAME,
"<br />")),
ifelse(is.na(data$EQ_PRIMARY),"", paste("<b>Magnitude: </b>",
data$EQ_PRIMARY,
"<br />")),
ifelse(is.na(data$DEATHS),"", paste("<b>Total Deaths: </b>",
data$DEATHS)))
}
#' This function creates the interative map widget for earthquake visualization
#'
#' @param data the raw dataset
#' @param annot_col the column of the raw dataset to be used for popup annotation on the widget
#' @return a leaflet object that displays earthquake locations on a map
#' @example eq_map(noaa, annot_col = "DATE")
#' @export
eq_map <- function(data, annot_col = "DATE") {
leaflet::leaflet() %>%
leaflet::addTiles() %>%
leaflet::addCircleMarkers(data = data,
lng = ~ LONGITUDE,
lat = ~ LATITUDE,
radius = 4,
popup = ~ paste(data[[annot_col]]))
}
# noaa %>%
# eq_clean_data() %>% eq_location_clean() %>%
# dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
# eq_map(annot_col = "DATE")
#
# noaa %>%
# eq_clean_data() %>% eq_location_clean() %>%
# dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
# dplyr::mutate(popup_text = eq_create_label(.)) %>%
# eq_map(annot_col = "popup_text")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.