knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The rationale of this package is to grant peer-grading for the Coursera course of Building Data Visualization Tools
. As a potentially useful byproduct, the code in this package contains a customized stat/geom
pair named *_hurricane
that can be used to visualize storm observation data. Particularly, provided data are arranged in an appropriate way, this geom
draws the regions of a storm observation corresponding to the same wind speed level, for the four quadrants defined by an origin point. The contour of the "iso-speed" levels are connected by a polygon
grid object.
The storm observation data that can be fed to *_hurricane
functions are based on the dataset available at Tropical cyclone EBTD. An R script describing the required data frame generating process is provided in the package.
The package contains the following files and folders:
{stat/geom}_hurricane
functions{stat/geom}_hurricane
functions, as well as the ike
dataset provided along with the packageike
dataset, generated by the data_cleaner.R script{stat/geom}_hurricane
functions, as well as the make_figure.R script adopted to produce the Figure belowgeom_hurricane
function in the make_figure.R scriptgeom_hurricane
functionknitr::include_graphics("../figures/ike-13sep.png")
The reference data of the tropical cyclons is provided in the EBTD database. The ike
data frame constitutes a subset of the aforementioned database and is provided along with this package. The format of the data frame is different from the raw data and is strictly required by the {stat/geom}_hurricane
functions. For convenience the ike
data frame is shown below:
library(magrittr) library(dplyr)
load(file = "../data/ike.rda")
ike
The ike
data frame is generated with the following code (see the data_cleaner.R script, in the resource folder):
# Load and tidy ebrtk data # library(magrittr) library(dplyr) library(readr) library(tidyr) library(stringr) library(lubridate) # # read source data ext_tracks_widths <- c(7, 10, 2, 2, 3, 5, 5, 6, 4, 5, 4, 4, 5, 3, 4, 3, 3, 3, 4, 3, 3, 3, 4, 3, 3, 3, 2, 6, 1) ext_tracks_colnames <- c("storm_id", "storm_name", "month", "day", "hour", "year", "latitude", "longitude", "max_wind", "min_pressure", "rad_max_wind", "eye_diameter", "pressure_1", "pressure_2", paste("radius_34", c("ne", "se", "sw", "nw"), sep = "_"), paste("radius_50", c("ne", "se", "sw", "nw"), sep = "_"), paste("radius_64", c("ne", "se", "sw", "nw"), sep = "_"), "storm_type", "distance_to_land", "final") ext_tracks <- read_fwf("ebtrk_atlc_1988_2015.txt", fwf_widths(ext_tracks_widths, ext_tracks_colnames), na = "-99") # # refactor quadrant radii features <- c("storm_name", "year", "month", "day", "hour", "latitude", "longitude") tmp <- ext_tracks %>% select(features, starts_with("radius_")) %>% filter(storm_name == "IKE") %>% gather(key, value, -features) %>% extract(key, c("wind_speed", "quadrant"), "(\\d+)_(..)") %>% spread(quadrant, value) # # add (remove) new (old) features ike <- tmp %>% mutate(date = as.character(make_datetime(as.integer(year), as.integer(month), as.integer(day), as.integer(hour)))) %>% mutate(longitude = -longitude) %>% mutate(storm_id = paste(str_to_title(storm_name), year, sep = "-")) %>% select(storm_id, date, latitude, longitude, wind_speed, ne, nw, se, sw)
The stat_hurricane
function builds the points, which form the contours of the wind radii, by means of the \link[geosphere]{destPoint} function. geom_hurricane
inherits from geom_polygon
. The default geom
associated to stat_hurricane
is geom_hurricane
, as shown by the following code chunk:
library(ggplot2) ike_1 <- ike %>% dplyr::filter(latitude > 29 & latitude < 30) ggplot(data = ike_1, mapping = aes(x = longitude, y = latitude)) + stat_hurricane(mapping = aes(x = longitude, y = latitude, r_ne = ne, r_se = se, r_sw = sw, r_nw = nw, colour = wind_speed), alpha = 0) + theme_minimal()
knitr::include_graphics("../figures/ex_stat_hurricane.png")
When adding a geom_hurricane
layer on top of a map object, as in the first figure, the boundaries of the latitude and longitude of the complete picture map is determined by the map object. In this case, if any points of the wind radii computed by geom_hurricane
exceed those limits, the resulting plot will be incorrect. It is advised to use the scale_radii
aestethic to reduce the size of the geom_hurricane
polygons or to use a less zoomed-in map object.
ggplot2::geom_polygon
function, version 2.2.1.9000ggplot2
package, Extending ggplot2geosphere
package, Introduction to the geosphere packageAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.