library(leaflet)
library(sf)
library(tidyverse)
library(maps)
library(dplyr)
meteorites <- read_csv("Meteorite_Landings.csv")
meteorites_ne <- meteorites |>
dplyr::filter(
reclat >= 37,
reclat <= 47.5,
reclong >= -80,
reclong <= -66,
!is.na(reclat),
!is.na(reclong),
reclat != 0,
reclong != 0,
!is.na(`mass (g)`),
`mass (g)` > 0
)
pal <- colorFactor(
palette = c("#FF6D00", "#B026FF"),
domain = c("Fell", "Found")
)
leaflet(meteorites_ne) |>
# Dark CARTO basemap
addTiles(
urlTemplate = paste0(
"https://basemaps.cartocdn.com/rastertiles/dark_all/{z}/{x}/{y}.png?key=",
Sys.getenv("CARTO_API_KEY")
),
attribution = '© OpenStreetMap contributors © CARTO'
) |>
# Set initial map extent
setView(
lng = -72.5,
lat = 43,
zoom = 6
) |>
# Meteorite markers
addCircleMarkers(
lng = ~reclong,
lat = ~reclat,
radius = 5,
color = ~pal(fall),
fillColor = ~pal(fall),
fillOpacity = 0.85,
stroke = TRUE,
weight = 0.5,
#Interactive pop-ups
popup = ~paste0(
"<b>", name, "</b><br>",
"<b>Classification:</b> ", recclass, "<br>",
"<b>Mass:</b> ", scales::comma(`mass (g)`), " g<br>",
"<b>Fall Type:</b> ", fall, "<br>",
"<b>Year:</b> ", year
),
label = ~name
) |>
# Legend
addLegend(
position = "bottomright",
pal = pal,
values = c("Fell", "Found"),
title = "Meteorite Fall Type",
opacity = 1
) |>
# Map title
addControl(
html = "
<h4 style='color:#4FC3F7;
background:rgba(255,255,255,0.85);
padding:8px 12px;
border-radius:6px;
font-size:16px;
font-weight:600;
margin:0;'>
Meteorite Discoveries in the Northeast U.S.
</h4>
",
position = "topright"
)
NASA. Meteorite Landings. https://data.nasa.gov/dataset/meteorite-landings