library(RCapstone) library(dplyr) library(ggplot2) library(readr) library(grid) library(lubridate) library(leaflet) library(scales)
Overview of the RCapstone
R package created for visualizing U.S. National Oceanographic and Atmospheric Administation's (NOAA) dataset of significant earthquakes. The data examined is from NOAA database.
You can install RCapstone from github with:
library(devtools) install_github("CarlosSilva34/RCapstone") library(RCapstone)
Exported functions available:
eq_clean_data()
eq_location_clean()
geom_timeline()
geom_timeline_label()
theme_timeline()
eq_create_label()
eq_map()
The first function cleans the data for the visualization. It creates a DATE column in Date
format, transforms latitude and longitude to numeric format and trims country from LOCATION_NAME.
filename <- system.file("extdata/signif.txt", package = "RCapstone") data <- readr::read_delim(filename, delim = "\t") eq_clean_data(data)
These functions use ggplot2
package to visualize earthquake timeline. Thegeom_timeline()
geom requires clean data. The aesthetics are x
with dates, optional y
for grouping by country,size
and color
. The geom_timeline_label()
function requires label
aesthetic. The theme_timeline()
geom was added for better visualization.
data %>% eq_clean_data() %>% filter(COUNTRY %in% c("USA", "CHINA"), YEAR >= 2000) %>% ggplot(aes(x = DATE, y = COUNTRY, color = as.numeric(TOTAL_DEATHS), size = as.numeric(EQ_PRIMARY) )) + geom_timeline() + geom_timeline_label(aes(label = LOCATION_NAME), n_max = 5) + theme_timeline() + labs(size = "Richter scale value", color = "# deaths")
These functions use leaflet
package to visualize earthquakes on a map using eq_map()
function. Optional annotations can be created using eq_create_label()
function. This creates an interactive map where user can click on individual points to get details.
```r data %>% eq_clean_data() %>% dplyr::filter(COUNTRY == "MEXICO" & 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.