| Title: | Network-Style Visualization of Directed Pairwise Relationships |
|---|---|
| Description: | Create network-style visualizations of pairwise relationships using custom edge glyphs built on top of 'ggplot2'. The package supports both statistical and non-statistical data and allows users to represent directed relationships. This enables clear, publication-ready graphics for exploring and communicating relational structures in a wide range of domains. The method was first used in Abu-Akel et al. (2021) <doi:10.1371/journal.pone.0245100>. Code is released under the MIT License; included datasets are licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0). |
| Authors: | Valentin Velev [cre, aut], Andreas Spitz [ctb] |
| Maintainer: | Valentin Velev <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-31 08:35:43 UTC |
| Source: | https://github.com/valentinsvelev/gglyph |
Generates custom mock data to be passed to gglyph::geom_glyph().
generate_mock_data( n_nodes = 5, n_edges = 7, n_groups = 1, statistical = FALSE, p_threshold = 0.05 )generate_mock_data( n_nodes = 5, n_edges = 7, n_groups = 1, statistical = FALSE, p_threshold = 0.05 )
n_nodes |
Number of nodes in the graph. Default is 5. |
n_edges |
Number of edges to generate. Default is 7. |
n_groups |
Number of groups (for faceting). Default is 1 (ungrouped). |
statistical |
If TRUE, generates mock p-values for edges. Default is FALSE. |
p_threshold |
The significance threshold for filtering edges. Default is 0.05. |
A data frame with mock data for nodes and edges.
# For non-grouped data mock_data <- generate_mock_data( n_nodes = 5, n_edges = 7, n_groups = 1, statistical = FALSE, p_threshold = 0.05 ) # For grouped data mock_data <- generate_mock_data( n_nodes = 5, n_edges = 7, n_groups = 3, statistical = TRUE, p_threshold = 0.05 )# For non-grouped data mock_data <- generate_mock_data( n_nodes = 5, n_edges = 7, n_groups = 1, statistical = FALSE, p_threshold = 0.05 ) # For grouped data mock_data <- generate_mock_data( n_nodes = 5, n_edges = 7, n_groups = 3, statistical = TRUE, p_threshold = 0.05 )
Create a network-style graph that illustrates directed pairwise relationships using custom edges.
geom_glyph( mapping = NULL, data = NULL, edge_size = 1, edge_colour = "grey", edge_fill = NULL, edge_alpha = 1, node_size = 1, node_colour = "black", node_fill = NULL, node_alpha = 1, node_shape = 21, node_spacing = 1, label_size = 12, group_label_size = 13, legend_title = NULL, legend_subtitle = NULL, ..., stat = "identity", position = "identity", na.rm = FALSE, show.legend = TRUE, inherit.aes = TRUE )geom_glyph( mapping = NULL, data = NULL, edge_size = 1, edge_colour = "grey", edge_fill = NULL, edge_alpha = 1, node_size = 1, node_colour = "black", node_fill = NULL, node_alpha = 1, node_shape = 21, node_spacing = 1, label_size = 12, group_label_size = 13, legend_title = NULL, legend_subtitle = NULL, ..., stat = "identity", position = "identity", na.rm = FALSE, show.legend = TRUE, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by aes(). You must supply mapping if there is no plot mapping. |
data |
A DataFrame with preprocessed data from either gglyph::preprocess_data_general() or gglyph::preprocess_data_statistical(). To be passed to ggplot2::ggplot(). |
edge_size |
A numeric scaling factor indicating the size/width of the edges. Default is 1. |
edge_colour |
Color(s) of the edge outlines. Can be a single string (for non-grouped data) or a vector of strings or a function (for grouped data). Default is "grey". |
edge_fill |
Color(s) for the edge fill. Can be a single string, a vector of strings, or a color function. If NULL, defaults to edge_colour. |
edge_alpha |
A numeric value indicating the transparency of the edges. Default is 1. |
node_size |
A numeric value indicating the size of the nodes. Default is 8. |
node_colour |
Color(s) of the node outlines. Can be a single string (for non-grouped data) or a vector of strings or a function (for grouped data). Default is "black". |
node_fill |
Color for the node fill. If NULL, defaults to node_colour. |
node_alpha |
A numeric value indicating the transparency of the nodes. Default is 1. |
node_shape |
A numeric value specifying the shape of the nodes, following ggplot2's shape specifications. Default is 21 (a circle with a border). |
node_spacing |
A numeric scaling factor for the distance between nodes. Values > 1 will push nodes further apart, while values < 1 will bring them closer. Default is 1. |
label_size |
A numeric value indicating the size of the node labels. Default is 12. |
group_label_size |
A numeric value indicating the size of group label. Default is 13. |
legend_title |
Title for the legend as a string. |
legend_subtitle |
Subtitle for the legend as a string. |
... |
Additional arguments passed to ggplot2 layer. |
stat |
The statistical transformation to use on the data for this layer. |
position |
A position adjustment to use on the data for this layer. |
na.rm |
If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed. |
show.legend |
Should this layer be included in the legends? Default is TRUE. |
inherit.aes |
If FALSE, overrides the default aesthetics, rather than combining with them. Default is FALSE. |
A ggplot2 layer with custom network-based graph.
# For non-grouped/-facetted plot data <- gglyph::generate_mock_data(n_groups = 1) ggplot2::ggplot(data = data) + gglyph::geom_glyph() ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = "purple", node_colour = "blue") ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = "purple", node_colour = "blue") + ggplot2::labs(title = "A beautiful glyph") # For grouped/facetted plot data <- gglyph::generate_mock_data(n_groups = 3) ggplot2::ggplot(data = data) + gglyph::geom_glyph() + ggplot2::facet_wrap(~ group) ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = viridis::viridis, node_colour = viridis::viridis) + ggplot2::facet_wrap(~ group) ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = viridis::viridis, node_colour = viridis::viridis) + ggplot2::facet_wrap(~ group) + ggplot2::labs(title = "Beautiful glyphs")# For non-grouped/-facetted plot data <- gglyph::generate_mock_data(n_groups = 1) ggplot2::ggplot(data = data) + gglyph::geom_glyph() ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = "purple", node_colour = "blue") ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = "purple", node_colour = "blue") + ggplot2::labs(title = "A beautiful glyph") # For grouped/facetted plot data <- gglyph::generate_mock_data(n_groups = 3) ggplot2::ggplot(data = data) + gglyph::geom_glyph() + ggplot2::facet_wrap(~ group) ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = viridis::viridis, node_colour = viridis::viridis) + ggplot2::facet_wrap(~ group) ggplot2::ggplot(data = data) + gglyph::geom_glyph(edge_colour = viridis::viridis, node_colour = viridis::viridis) + ggplot2::facet_wrap(~ group) + ggplot2::labs(title = "Beautiful glyphs")
Results of pairwise t-tests (with Bonferroni correction) performed on a subset from the PISA 2022 data.
data(pisa_2022)data(pisa_2022)
A data frame with 492 rows and 3 variables:
fromCategory A of educational level (ISCED) attained by the parents of the respondent (character).
toCategory B of educational level (ISCED) attained by the parents of the respondent (character).
groupCountry of the respondent (character).
sigp-value of the pairwise t-test (numeric).
Data obtained from:
OECD (2023). PISA 2022 Database [Data Set]. Zenodo. doi:10.5281/zenodo.13382904
Licensed under CC BY 4.0: https://creativecommons.org/licenses/by/4.0/
Additional reference(s) for further reading:
OECD (2024). PISA 2022 Technical Report. OECD Publishing, Paris. doi:10.1787/01820d6d-en
data(pisa_2022) head(pisa_2022)data(pisa_2022) head(pisa_2022)
Prepare general/non-statistical data for plotting with gglyph::geom_glyph().
process_data_general(data, from = "from", to = "to", group = NULL)process_data_general(data, from = "from", to = "to", group = NULL)
data |
A DataFrame or tibble containing the input data to be processed. |
from |
A string indicating the column name for the start nodes. |
to |
A string indicating the column name for the end nodes. |
group |
A string indicating the column name for the grouping variable. |
A DataFrame with the preprocessed data that is to be passed to gglyph::geom_glyph().
data(sipri_milex_1995_2023) # For non-grouped data processed_data <- process_data_general( data = sipri_milex_1995_2023, from = "from", to = "to" ) # For grouped data processed_data <- process_data_general( data = sipri_milex_1995_2023, from = "from", to = "to", group = "group" )data(sipri_milex_1995_2023) # For non-grouped data processed_data <- process_data_general( data = sipri_milex_1995_2023, from = "from", to = "to" ) # For grouped data processed_data <- process_data_general( data = sipri_milex_1995_2023, from = "from", to = "to", group = "group" )
Prepare statistical data for plotting with gglyph::geom_glyph().
process_data_statistical( data, from = "from", to = "to", group = NULL, sig = "sig", thresh = 0.05 )process_data_statistical( data, from = "from", to = "to", group = NULL, sig = "sig", thresh = 0.05 )
data |
A DataFrame or tibble containing the input data to be processed. |
from |
A string indicating the column name for the start nodes. |
to |
A string indicating the column name for the end nodes. |
group |
A string indicating the column name for the grouping variable. |
sig |
A string indicating the column name for the significance level. |
thresh |
A single number indicating the significance threshold. Default is 0.05. |
A DataFrame with the preprocessed data that is to be passed to gglyph::geom_glyph().
data(pisa_2022) # For non-grouped data processed_data <- process_data_statistical( data = pisa_2022, from = "from", to = "to", sig = "sig", thresh = 0.05 ) # For grouped data processed_data <- process_data_statistical( data = pisa_2022, from = "from", to = "to", sig = "sig", group = "group", thresh = 0.05 )data(pisa_2022) # For non-grouped data processed_data <- process_data_statistical( data = pisa_2022, from = "from", to = "to", sig = "sig", thresh = 0.05 ) # For grouped data processed_data <- process_data_statistical( data = pisa_2022, from = "from", to = "to", sig = "sig", group = "group", thresh = 0.05 )
A subset of the SIPRI Military Expenditure 1949-2023 data.
data(sipri_milex_1995_2023)data(sipri_milex_1995_2023)
A data frame with 77 rows and 3 variables:
fromName of country A (character).
toName of country B (character).
groupYear (numeric).
Data obtained from:
SIPRI (2025). SIPRI Military Expenditure Database [Data Set]. doi:10.55163/CQGC9685
Licensed under CC BY 4.0: https://creativecommons.org/licenses/by/4.0/
data(sipri_milex_1995_2023) head(sipri_milex_1995_2023)data(sipri_milex_1995_2023) head(sipri_milex_1995_2023)