Title: | Create Glyph-Maps of Spatiotemporal Data |
---|---|
Description: | Provides 'ggplot2' extensions to construct glyph-maps for visualizing seasonality in spatiotemporal data. See the Journal of Statistical Software reference: Zhang, H. S., Cook, D., Laa, U., Langrené, N., & Menéndez, P. (2024) <doi:10.18637/jss.v110.i07>. The manuscript for this package is currently under preparation and can be found on GitHub at <https://github.com/maliny12/paper-sugarglider>. |
Authors: | Maliny Po [aut, cre, cph] , S. Nathan Yang [aut] , H. Sherry Zhang [ctb] , Dianne Cook [ctb] |
Maintainer: | Maliny Po <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.3 |
Built: | 2024-10-25 05:34:21 UTC |
Source: | CRAN |
This function introduces a custom layer to a ggplot, employing 'glyph boxes' to visually represent individual glyph. Users can specify various aesthetics including alpha, height, width, color, line type, and fill to customize the appearance.
add_glyph_boxes( mapping = NULL, data = NULL, stat = "identity", position = "identity", x_major = NULL, y_major = NULL, height = "default", width = "default", fill = "white", linewidth = 0.1, inherit.aes = TRUE, show.legend = NA, ... )
add_glyph_boxes( mapping = NULL, data = NULL, stat = "identity", position = "identity", x_major = NULL, y_major = NULL, height = "default", width = "default", fill = "white", linewidth = 0.1, inherit.aes = TRUE, show.legend = NA, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. If |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
x_major , y_major
|
Aesthetics to map plot coordinates for major and minor glyph components. |
height |
The height of each glyph. The 'default' is calculated using the ratio (1:1.618) relative to the 'width', to maintain a consistent aspect ratio. |
width |
The width of each glyph. The 'default' is set to the smallest distance between two consecutive coordinates, converted from meters to degrees of latitude using the Haversine method. |
fill |
The color used to fill the glyph box. |
linewidth |
The thickness of the glyph box. |
inherit.aes |
If |
show.legend |
logical. Should this layer be included in the legends?
|
... |
Additional arguments passed on to function. |
A layer object that can be added to a ggplot.
This function adds a custom legend layer to a ggplot object using the specified aesthetics and parameters.
add_glyph_legend( mapping = NULL, data = NULL, stat = "identity", position = "identity", show.legend = NA, x_minor = NULL, x_scale = identity, y_scale = identity, fill = "black", color = "black", linewidth = 0.5, alpha = 0.8, global_rescale = TRUE, inherit.aes = TRUE, ... )
add_glyph_legend( mapping = NULL, data = NULL, stat = "identity", position = "identity", show.legend = NA, x_minor = NULL, x_scale = identity, y_scale = identity, fill = "black", color = "black", linewidth = 0.5, alpha = 0.8, global_rescale = TRUE, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
x_minor |
Aesthetics to map plot coordinates for major and minor glyph components. |
x_scale , y_scale
|
The scaling function applied to each set of minor values within a grid cell. Defaults to 'identity'. |
fill |
The fill color for the geometric object. |
color |
The color of the geometric object's border or line. |
linewidth |
The width of the geometric object's line. |
alpha |
The transparency level of the geometric object, ranging from 0 (fully transparent) to 1 (fully opaque). |
global_rescale |
A setting that determines whether to perform rescaling globally or on individual glyphs. |
inherit.aes |
If |
... |
Additional arguments passed on to function. |
A ggplot2 layer.
This function draw reference lines that include both major and minor division markers.
add_ref_lines( mapping = NULL, data = NULL, stat = "identity", position = "identity", show.legend = NA, x_major = NULL, y_major = NULL, height = "default", width = "default", inherit.aes = TRUE, linewidth = 0.1, ... )
add_ref_lines( mapping = NULL, data = NULL, stat = "identity", position = "identity", show.legend = NA, x_major = NULL, y_major = NULL, height = "default", width = "default", inherit.aes = TRUE, linewidth = 0.1, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. If |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
x_major , y_major
|
Aesthetics to map plot coordinates for major and minor glyph components. |
height |
The height of each glyph. The 'default' is calculated using the ratio (1:1.618) relative to the 'width', to maintain a consistent aspect ratio. |
width |
The width of each glyph. The 'default' is set to the smallest distance between two consecutive coordinates, converted from meters to degrees of latitude using the Haversine method. |
inherit.aes |
If |
linewidth |
The thickness of the reference line. |
... |
Additional arguments passed on to function. |
A ggplot2 layer.
This dataset contains aggregated monthly average temperatures (minimum and maximum) and precipitation for selected Australian weather stations for the year 2022. Stations were selected based on specific criteria such as operational status and completeness of data for the year.
aus_temp
aus_temp
A data frame with the following columns:
Station ID.
Longitude of the station.
Latitude of the station.
Month for the aggregated data.
Monthly average minimum temperature (in degrees Celsius).
Monthly average maximum temperature (in degrees Celsius).
Monthly average precipitation (in mm).
GHCN Daily data via 'meteo_pull_monitors' from the 'rnoaa' package.
This dataset contains information on the minimum and maximum number of flights that originated from the top 10 U.S. airports with the highest number of flight cancellations. The airports included are Denver (DEN), Orlando (MCO), Seattle (SEA), Atlanta (ATL), Dallas/Fort Worth (DFW), Chicago O'Hare (ORD), Las Vegas (LAS), Los Angeles (LAX), and Phoenix (PHX).
flights
flights
'flights' A data frame with 120 rows and 6 columns:
The origin airport for that flight
The month of the flight
Longitude of the airport
Latitude of the airport
The minimum number of flights that originated from the airport
The maximum number of flights that originated from the airport
This function creates a ribbon geometry designed to display glyphs based on the combination of 'x_major' and 'y_major'. For each 'x_minor' value, 'geom_glyph_ribbon()' displays a y interval defined by 'ymin_minor' and 'ymax_minor'.
geom_glyph_ribbon( mapping = NULL, data = NULL, show.legend = NA, stat = "identity", position = "identity", x_major = NULL, y_major = NULL, x_minor = NULL, ymin_minor = NULL, ymax_minor = NULL, height = "default", width = "default", x_scale = identity, y_scale = identity, global_rescale = TRUE, inherit.aes = TRUE, ... )
geom_glyph_ribbon( mapping = NULL, data = NULL, show.legend = NA, stat = "identity", position = "identity", x_major = NULL, y_major = NULL, x_minor = NULL, ymin_minor = NULL, ymax_minor = NULL, height = "default", width = "default", x_scale = identity, y_scale = identity, global_rescale = TRUE, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
show.legend |
logical. Should this layer be included in the legends?
|
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
x_major , y_major , x_minor , ymin_minor , ymax_minor
|
Each combination of 'x_major' and 'y_major' forms a unique grid cell. 'ymin_minor' and 'ymax_minor' define the lower and upper bounds of the geom_ribbon. |
height |
The height of each glyph. The 'default' is calculated using the ratio (1:1.618) relative to the 'width', to maintain a consistent aspect ratio. |
width |
The width of each glyph. The 'default' is set to the smallest distance between two consecutive coordinates, converted from meters to degrees of latitude using the Haversine method. |
x_scale , y_scale
|
The scaling function applied to each set of minor values within a grid cell. Defaults to 'identity'. |
global_rescale |
A setting that determines whether to perform rescaling globally or on individual glyphs. |
inherit.aes |
If |
... |
Additional arguments passed on to function. |
A ggplot object.
library(ggplot2) # Basic glyph map with base map and custom theme aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_ribbon() + ggthemes::theme_map() # Adjust width and height of the glyph aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_ribbon(width = rel(4.5), height = rel(3)) + ggthemes::theme_map() # Extend glyph map with reference box and line aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + add_glyph_boxes() + add_ref_lines() + geom_glyph_ribbon() + ggthemes::theme_map()
library(ggplot2) # Basic glyph map with base map and custom theme aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_ribbon() + ggthemes::theme_map() # Adjust width and height of the glyph aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_ribbon(width = rel(4.5), height = rel(3)) + ggthemes::theme_map() # Extend glyph map with reference box and line aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + add_glyph_boxes() + add_ref_lines() + geom_glyph_ribbon() + ggthemes::theme_map()
This function enables the creation of segment glyphs by defining major coordinates (longitude and latitude) and minor segment structures within a grid cell. Each glyph's appearance can be customized by specifying its height, width, and scaling, allowing for flexible data representation in a visual context.
geom_glyph_segment( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, yend_minor = NULL, width = "default", x_scale = identity, y_scale = identity, height = "default", global_rescale = TRUE, show.legend = NA, inherit.aes = TRUE )
geom_glyph_segment( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, yend_minor = NULL, width = "default", x_scale = identity, y_scale = identity, height = "default", global_rescale = TRUE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
x_major , x_minor , y_major , y_minor , yend_minor
|
The name of the
variable (as a string) for the major and minor x and y axes. |
width |
The width of each glyph. The 'default' is set to the smallest distance between two consecutive coordinates, converted from meters to degrees of latitude using the Haversine method. |
y_scale , x_scale
|
The scaling function to be applied to each set of
minor values within a grid cell. The default is |
height |
The height of each glyph. The 'default' is calculated using the ratio (1:1.618) relative to the 'width', to maintain a consistent aspect ratio. |
global_rescale |
Determines whether or not the rescaling is performed globally or separately for each individual glyph. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a ggplot object
library(ggplot2) # Basic glyph map with base map and custom theme aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, y_minor = tmin, yend_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_segment() + ggthemes::theme_map() # Adjust width and height of the glyph aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, y_minor = tmin, yend_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_segment(width = rel(4.5), height = rel(3)) + ggthemes::theme_map() # Extend glyph map with reference box and line aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, y_minor = tmin, yend_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + add_glyph_boxes() + add_ref_lines() + geom_glyph_segment() + ggthemes::theme_map()
library(ggplot2) # Basic glyph map with base map and custom theme aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, y_minor = tmin, yend_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_segment() + ggthemes::theme_map() # Adjust width and height of the glyph aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, y_minor = tmin, yend_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + geom_glyph_segment(width = rel(4.5), height = rel(3)) + ggthemes::theme_map() # Extend glyph map with reference box and line aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, y_minor = tmin, yend_minor = tmax)) + geom_sf(data = ozmaps::abs_ste, fill = "grey95", color = "white",inherit.aes = FALSE) + add_glyph_boxes() + add_ref_lines() + geom_glyph_segment() + ggthemes::theme_map()
This dataset contains aggregated monthly average temperatures (minimum and maximum) and precipitation for selected Australian weather stations for the years 2021 and 2022. It provides a broader historical perspective compared to 'aus_temp'. Stations were selected based on operational status and data completeness.
historical_temp
historical_temp
A data frame with the following columns:
Station ID.
Longitude of the station.
Latitude of the station.
Month for the aggregated data.
Year for the aggregated data, either 2021 or 2022.
Monthly average minimum temperature (in degrees Celsius).
Monthly average maximum temperature (in degrees Celsius).
Monthly average precipitation (in mm).
GHCN Daily data via 'meteo_pull_monitors' from the 'rnoaa' package.
'theme_glyph()' provides a customized theme for glyph maps, built on top of ‘theme_map()' from 'ggthemes'. It adjusts the plot’s appearance, including the legend position, text styles, and background settings, to create a clean, visually consistent layout for glyph visualizations.
theme_glyph( control = list(plot.title = rel(1.5), plot.subtitle = rel(1.3), plot.caption = rel(1), legend.text = rel(1), legend.title = rel(1)) )
theme_glyph( control = list(plot.title = rel(1.5), plot.subtitle = rel(1.3), plot.caption = rel(1), legend.text = rel(1), legend.title = rel(1)) )
control |
A list specifying the relative font sizes for different plot elements. The list can contain the following components:
|
This theme includes:
Legend positioned inside the plot, at the bottom left corner.
Horizontal legend direction with 'mono' font for text.
Centered plot titles with bold, 'mono' font.
'mono' fonts for subtitles and captions.
White background for both the panel and plot.
A ggplot2 theme object with customized settings for glyph plots.
[ggthemes::theme_map()], [ggplot2::theme()]
library(ggplot2) library(ozmaps) aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = abs_ste, fill = "antiquewhite", inherit.aes = FALSE, color = "white") + add_glyph_boxes() + add_ref_lines() + geom_glyph_ribbon() + theme_glyph()
library(ggplot2) library(ozmaps) aus_temp |> ggplot(aes(x_major = long, y_major = lat, x_minor = month, ymin_minor = tmin, ymax_minor = tmax)) + geom_sf(data = abs_ste, fill = "antiquewhite", inherit.aes = FALSE, color = "white") + add_glyph_boxes() + add_ref_lines() + geom_glyph_ribbon() + theme_glyph()
This data set provides a comprehensive hourly summary of patronage at each train station in Victoria for the fiscal year 2023-2024. The number of patronage is definded by the total number of boarding and alighting at each station. This data set includes detailed breakdowns by day types such as weekdays, weekends, and holidays (including school and public holidays). Note the influence of station closures which may skew or omit data on particular days.
data(train)
data(train)
A data frame with each row representing aggregated monthly data per station, containing:
Name of the train station.
Operating hour ranging from 5AM to 12PM.
Longitude of the train station.
Latitude of the train station.
Number of unique services passing through the station.
Transportation mode, such as 'Metro', 'VLine', or both.
Minimum hourly patronage on a typical weekday.
Maximum hourly patronage on a typical weekday.
Minimum hourly patronage on weekends.
Maximum hourly patronage on weekends.
Minimum hourly patronage during school and public holidays.
Maximum hourly patronage during school and public holidays.
Stations with incomplete entries due to closure are not included in this dataset.
https://discover.data.vic.gov.au/dataset/train-service-passenger-counts