knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The jyjekNOAA package is R-package for prepare and plot and map vizualizate for NOAA Significant Earthquake Database. This package was build for Coursera Mastering Softfawe Development in R specialization
For install jyjekNOAA
package, you must have installed devtools
package.
if(!("devtools" %in% installed.packages())){install.packages("devtools")} devtools::install_github("jyjek/jyjekNOAA") library(jyjekNOAA)
The package has dependices. For correct work also must be installed next packages:
library(jyjekNOAA) library(dplyr) library(ggplot2) library(lubridate) library(purrr) library(glue) library(stringr)
You can load NOAA Significant Earthquake Database:
NOAA_quakes<-jyjekNOAA::NOAA_quakes
For more information about dataset:
?jyjekNOAA::NOAA_quakes
After laoding dataset you can clean data to the tidy format. Function eq_clean_data()
transform dataset to the correct Date
format and Location Name.
NOAA_quakes%>% eq_clean_data()%>% head()
One of the main target of this package is building Timeline geom geom_timeline
using ggplot2
package. This function plot timeline for choosed Country and Time values of significant earthquakes with points colored and sized by number of deaths and Richter scale strength. X-axis is Year
of accidente, and choosed Countrys
on Y-axis.
Second ggplot2
geom is geom_timeline_label
. It's similar to the geom_timeline
but with label of top_n
earthquakes for each choosed Country
by mangnitude.
Function NOAA_thm
add theme for ggplot2
. This function make plot more pretty.
For example geom_timeline
:
NOAA_quakes%>% eq_clean_data()%>% dplyr::filter(COUNTRY %in% c('CHINA','MEXICO')) %>% dplyr::filter(DATE > '2010-01-01') %>% ggplot2::ggplot() + geom_timeline(aes(x = DATE, y = COUNTRY, size = as.numeric(EQ_PRIMARY), color = as.numeric(TOTAL_DEATHS))) + guides(size = guide_legend(order=1))+ scale_color_continuous(name = '# deaths') + scale_size_continuous(name = 'Richter scale value')+ NOAA_thm()
For example geom_timeline
:
NOAA_quakes%>% eq_clean_data()%>% dplyr::filter(COUNTRY %in% c('USA', 'JAPAN')) %>% dplyr::filter(DATE > '2000-01-01') %>% ggplot() + geom_timeline(aes(x = DATE, y = COUNTRY, color = as.numeric(TOTAL_DEATHS), size = as.numeric(EQ_PRIMARY))) + geom_timeline_label(aes(x = DATE, y = COUNTRY, magnitude = as.numeric(EQ_PRIMARY), label = LOCATION_NAME, n_max = 5)) + guides(size = guide_legend(order=1))+ scale_size_continuous(name = 'Richter scale value') + scale_color_continuous(name = '# of deaths') + NOAA_thm()
Call the function eq_map
with eq_clean_data()
for visualization leaflet
Map with choosed Country
and Dates
.
NOAA_quakes%>% eq_clean_data()%>% dplyr::filter(COUNTRY == 'MEXICO') %>% dplyr::filter(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.