We will be looking at an interactive map of volcano eruptions that have occurred in the United States. The Smithsonian Institution collects data on volcanic eruptions from all around the world. They update their data as eruptions occur around the world.
## data preparation
The smithsonian Institution website includes an option which allows users to enter in a preferred country and a preferred eruption category, which filters the data to the users input. To generate this data I selected “United States of America” for the country, and ” confirmed eruption” for eruption category. I then turned the resulting excel sheet into a csv file.
Us_Volcanoes <- read_csv("C:/Users/danny/OneDrive/Desktop/Intro to R/GVP_Eruption_Results.csv")
Now that we have the data into a data frame we can look at the structure of the data as shown below:
str(Us_Volcanoes)
## spec_tbl_df [1,083 x 24] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Volcano Number : num [1:1083] 332010 312030 284170 311120 312070 ...
## $ Volcano Name : chr [1:1083] "Kilauea" "Pavlof" "Pagan" "Great Sitkin" ...
## $ Eruption Number : num [1:1083] 22416 22411 22409 22401 22393 ...
## $ Eruption Category : chr [1:1083] "Confirmed Eruption" "Confirmed Eruption" "Confirmed Eruption" "Confirmed Eruption" ...
## $ Area of Activity : chr [1:1083] NA NA NA NA ...
## $ VEI : num [1:1083] NA NA NA NA NA NA 0 3 1 3 ...
## $ VEI Modifier : chr [1:1083] NA NA NA NA ...
## $ Start Year Modifier : chr [1:1083] NA NA NA NA ...
## $ Start Year : num [1:1083] 2021 2021 2021 2021 2021 ...
## $ Start Year Uncertainty : num [1:1083] NA NA NA NA NA NA NA NA NA NA ...
## $ Start Month : num [1:1083] 9 8 7 5 2 2 12 6 12 7 ...
## $ Start Day Modifier : chr [1:1083] NA NA NA NA ...
## $ Start Day : num [1:1083] 29 5 29 25 28 2 20 1 7 23 ...
## $ Start Day Uncertainty : num [1:1083] NA NA NA NA NA 2 NA NA NA NA ...
## $ Evidence Method (dating): chr [1:1083] "Historical Observations" "Historical Observations" "Historical Observations" "Historical Observations" ...
## $ End Year Modifier : chr [1:1083] ">" ">" NA ">" ...
## $ End Year : num [1:1083] 2022 2022 2021 2022 2021 ...
## $ End Year Uncertainty : num [1:1083] NA NA NA NA NA NA NA NA NA NA ...
## $ End Month : num [1:1083] 3 3 9 3 4 3 5 6 6 5 ...
## $ End Day Modifier : chr [1:1083] NA NA NA NA ...
## $ End Day : num [1:1083] 17 17 6 17 5 17 23 1 19 4 ...
## $ End Day Uncertainty : num [1:1083] NA NA NA NA NA NA NA NA NA NA ...
## $ Latitude : num [1:1083] 19.4 55.4 18.1 52.1 56.2 ...
## $ Longitude : num [1:1083] -155 -162 146 -176 -159 ...
## - attr(*, "spec")=
## .. cols(
## .. `Volcano Number` = col_double(),
## .. `Volcano Name` = col_character(),
## .. `Eruption Number` = col_double(),
## .. `Eruption Category` = col_character(),
## .. `Area of Activity` = col_character(),
## .. VEI = col_double(),
## .. `VEI Modifier` = col_character(),
## .. `Start Year Modifier` = col_character(),
## .. `Start Year` = col_double(),
## .. `Start Year Uncertainty` = col_double(),
## .. `Start Month` = col_double(),
## .. `Start Day Modifier` = col_character(),
## .. `Start Day` = col_double(),
## .. `Start Day Uncertainty` = col_double(),
## .. `Evidence Method (dating)` = col_character(),
## .. `End Year Modifier` = col_character(),
## .. `End Year` = col_double(),
## .. `End Year Uncertainty` = col_double(),
## .. `End Month` = col_double(),
## .. `End Day Modifier` = col_character(),
## .. `End Day` = col_double(),
## .. `End Day Uncertainty` = col_double(),
## .. Latitude = col_double(),
## .. Longitude = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
The data consists of 1083 observations and 24 variables. We will only keep the name, VEI, Start Year, Start Month, Start Day, End Year, End Month, End Day, latitude, and longitude variables in our dataset.
Us_Volcanoes %>% select(`Volcano Name`, VEI, `Start Year`, `Start Month`, `Start Day`, `End Year`, `End Month`, `End Day`, Latitude, Longitude) -> Us_Volcanoes
Eruption_start_day <- as.Date(with(Us_Volcanoes,paste(`Start Year`, `Start Month`, `Start Day`, sep = "-")), "%Y-%m-%d")
Eruption_end_day <- as.Date(with(Us_Volcanoes,paste(`End Year`, `End Month`, `End Day`, sep = "-")), "%Y-%m-%d")
total_days_erupting <- Eruption_end_day -Eruption_start_day
Us_Volcanoes %>% mutate(number_of_days_erupting = total_days_erupting) -> Us_Volcanoes
Now we only have 11 variables in our data.We now make the interactive map of the locations where volcanoes have erupted in the US:
Us_Volcanoes_map <- leaflet() %>% addTiles() %>% addMarkers(data = Us_Volcanoes, popup = paste("Name:", Us_Volcanoes$`Volcano Name`, "<br>", "Volcanic Explositivity Index:", Us_Volcanoes$VEI, "<br>", "Eruption Start:", Eruption_start_day, "<br>", "Number of days Erupting:", Us_Volcanoes$number_of_days_erupting, "<br>"), clusterOptions = markerClusterOptions())
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively
Us_Volcanoes_map
We can see from this map that unsurprisingly all of the volcanic eruptions in the US have occurred in the western states, or on islands located in the ring of fire in the pacific ocean.