Meteorite Landing Sites

This documents presents the code for map available at: https://juliahoffman.neocities.org/week2.html. It is a part of fulfillment of a Data Products course in Coursera Data Science Specialization by Johns Hopkins University. I downloaded data from Kaggle: https://www.kaggle.com/nasa/meteorite-landings to have something interesting to present in my project.

I hope you enjoy it.

Loading and Cleaning Data

myfile <- "meteorite-landings.csv"
meteorites <- read.csv(file = "meteorite-landings.csv", header = TRUE, sep = ",")
meteorites <- meteorites %>% rename(lng=reclong,lat=reclat)
meteorites <- meteorites[complete.cases(meteorites),] 

meteorites <- meteorites[!duplicated(meteorites[,8:9]),] %>% 
filter(year>=860 & year<=2016) %>% 
filter(lng<=180 & lng>=-180 & (lat!=0 | lng!=0)) %>% 
mutate(X=paste0("<strong>Name: </strong>", 
                  name,
                  "<br><strong>Class: </strong>",
                  recclass,
                  "<br><strong>Mass (g): </strong>",
                  mass,
                  "<br>",
                  fall,"<strong> in year: </strong>",
                  year))

Making the Map

The The Meteoritical Society collects data on meteorites that have fallen to Earth from outer space. The data shown on the map below includes the location, mass, composition, and fall year for over 45,000 meteorites.

The map shows landings of meteorites. It can be zoomed in and out. Each icon depicts a landing site and provides information listed below:

name: the name of the meteorite (typically a location, often modified with a number, year, composition, etc)
class: the class of the meteorite; one of a large number of classes based on physical, chemical, and other characteristics
mass: the mass of the meteorite, in grams
Fell: the meteorite’s fall was observed
Found: the meteorite’s fall was not observed
year: the year the meteorite fell, or the year it was found or observed falling

The size of the icon corresponds to the meteorite size.

I focused the map on the US, but you can go wherever you like!

labs <- as.list(meteorites$X)

meteorIcon <- makeIcon(
        iconUrl=ifelse(meteorites$fall=="Found",
                "https://d30y9cdsu7xlg0.cloudfront.net/png/387172-200.png",
                "https://cdn3.iconfinder.com/data/icons/nature-life-in-color/128/meteor-512.png"),
        iconWidth=10*log10(meteorites$mass),
        iconHeight=10*log10(meteorites$mass),
        iconAnchorX=0, iconAnchorY=0
)

html_legend <- "<img src='https://d30y9cdsu7xlg0.cloudfront.net/png/387172-200.png' height='25' width='25'>Found<br/>
<img src='https://cdn3.iconfinder.com/data/icons/nature-life-in-color/128/meteor-512.png' height='25' width='25'>Fell"

my_map <- meteorites %>% leaflet() %>%
          addTiles() %>% setView(lng=-102.009078,lat=40.499276, zoom = 4) %>%
          addMarkers(clusterOptions=markerClusterOptions(), 
                     icon=meteorIcon,label = lapply(labs, HTML)) %>%
          addControl(html = html_legend, position = "topright")
## Assuming 'lng' and 'lat' are longitude and latitude, respectively
#                     
my_map

Publishing

To save the map as .html file, you can use the code below. I created a small webpage: https://juliahoffman.neocities.org/week2.html and inserted the output of this code there.

library(htmlwidgets)
saveWidget(widget = my_map, file = "my_map.html")