library(MasterRcap) library(magrittr) library(ggplot2) library(grid) options(width = 120)
Read and clean the data using eq_clean_data
function
raw_data_fn <- file.path(system.file("extdata", package="MasterRcap"),"signif.txt") data <- eq_clean_data(raw_data_fn) str(data)
The follong snippet draws earthquakes observed in the US and Canada from 2000
eq_clean_data() %>% dplyr::filter(YEAR > 2000 & !IS_BC & COUNTRY %in% c("USA", "CANADA")) %>% dplyr::mutate(TOTAL_DEATHS = as.numeric(TOTAL_DEATHS), EQ_PRIMARY = as.numeric(EQ_PRIMARY)) %>% ggplot2::ggplot(ggplot2::aes(x = DATE, y = COUNTRY, colour = TOTAL_DEATHS, size = EQ_PRIMARY )) + geom_timeline() + theme_timeline() + labs(size = "Richter scale value", color = "# deaths", fill = "# deaths")
The follong snippet draws earthquakes observed in the US and Canada from 2000 using:
geom_timeline
as previously to draw the timeline
geom_timeline_label
to add the labels.`
eq_clean_data() %>% dplyr::filter(YEAR > 2000 & !IS_BC & COUNTRY %in% c("USA", "CANADA")) %>% dplyr::mutate(TOTAL_DEATHS = as.numeric(TOTAL_DEATHS), EQ_PRIMARY = as.numeric(EQ_PRIMARY)) %>% ggplot2::ggplot(ggplot2::aes(x = DATE, y = COUNTRY, colour = TOTAL_DEATHS, size = EQ_PRIMARY )) + geom_timeline() + theme_timeline() + labs(size = "Richter scale value", color = "# deaths") + geom_timeline_label(ggplot2::aes(label = LOCATION_NAME), n_max = 3)
The follong snippet map the earthquakes observed in the Mexico from 2000. It uses
the input that we saw previously
the eq_map
function that draw a circle at each earthquake
* the eq_create_label
function that create labels.
eq_clean_data() %>% dplyr::filter(YEAR > 2000 & !IS_BC & COUNTRY %in% c("MEXICO")) %>% 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.