Volcano Eruptions
Static map with ggplot2
, Interactive map with leaflet
, Animated map with gganimate
Notable topics: Static map with ggplot2
, Interactive map with leaflet
, Animated map with gganimate
Recorded on: 2020-05-11
Timestamps by: Eric Fletcher
Screencast
Timestamps
Change the last_eruption_year
into years_ago
by using mutate
from the dplyr
package with years_ago = 2020 - as.numeric(last_eruption_year))
. In the plot David includes +1
to account for 0 values in the years_ago
variable.
Use str_detect
from the stringr
package to search the volcano_name
variable for Vesuvius
when not sure if spelling is correct.
Use the longitude
and latitude
to create a world map showing where the volcanoes are located.
Use fct_lump
from theforcats
package to lump together all primary_volcano_type
factor levels except for the n
most frequent.
Use str_remove
from the stringr
package with the regular expression "\\(.\\)"
to remove the parentheses.
Use the leaflet
package to create an interactive map with popup information about each volcano.
Use glue
from the glue
package to create an HTML
string by concatenating volcano_name
and primary_volcano_type
between HTML <p></p> tags
.
Use the DT
package to turn the leaflet
popup information into a datatable
.
Use str_replace_all
fromt he stringr
package to replace all the underscores _
in volcano_name
with space. Then use str_to_title
from the stringr
package to convert the volcano_name
variable to title case.
Use kable
with format = HTML
from the knitr
package instead of DT
to make turning the data into HTML
much easier.
Use paste0
from base
R to bold the Volcano Name
, Primary Volcano Type
, and Last Eruption Year
in the leaflet
popup.
Use replace_na
from the tidyr
package to replace unknown
with NA
.
Use addMeasure
from the leaflet
package to add a tool to the map that allows for the measuring of distance between points.
Use colorNumeric
from the leaflet
package to color the points based on their population within 5km
. To accomplish this, David creates 2 new variables: 1) transformed_pop
to get the population on a log2
scale & 2) pop_color
which uses the colorNumeric
function to generate the color hex values based on transformed_pop
.
Use the gganimate
package to create an animated map.
Use geom_point
from the ggplot2
package with size = .00001 * 10 ^ vei
so the size of the points are then proportional to the volume
metrics provided in the Volcano Eruption Index
. The metrics are in Km^3
.
Use scale_size_continuous
from the ggplot2
package with range = c(.1, 6)
to make the smaller points smaller and larger points larger.
Use scale_color_gradient2
from the ggplot2
package to apply color gradient to each point based on the volcano size and whether its low or high.
Summary of screencast while waiting for gganimate
map to render.
Also, brief discussion on using transition_reveal
instead of transition_time
to keep the point on the map instead of replacing them in each frame.