library(leaflet)
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)))
}
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]]))
}
new_noaa <- noaa %>% dplyr::mutate(popup_text=eq_create_label(.))
eq_map(new_noaa, annot_col ="COUNTRY")
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.