| Title: | Icon-Based Population Charts and Plots for 'ggplot2' |
|---|---|
| Description: | Create engaging population and point plots charts in R. 'ggpop' allows users to represent population data and points proportionally using customizable icons, facilitating the creation of circular representative population charts as well as any point-plots. |
| Authors: | Jorge A. Roa-Contreras [aut, cre] (ORCID: <https://orcid.org/0000-0002-3972-9793>), Ralitza Soultanova [aut] (ORCID: <https://orcid.org/0009-0000-9324-5653>), Fernando Alarid-Escudero [aut] (ORCID: <https://orcid.org/0000-0001-5076-1172>), Carlos Pineda-Antunez [aut] (ORCID: <https://orcid.org/0000-0002-8352-7080>) |
| Maintainer: | Jorge A. Roa-Contreras <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.7.1 |
| Built: | 2026-05-18 05:57:13 UTC |
| Source: | https://github.com/jurjoroa/ggpop |
ggpop is a ggplot2 extension for creating icon-based population charts
and pictogram plots. Use geom_pop() and geom_icon_point() to visualize
proportion and population data with 2,000+ Font Awesome icons.
geom_pop() – proportional icon grids
geom_icon_point() – icon scatter plots
process_data() – prepare count data for plotting
fa_icons() – search Font Awesome icon names
theme_pop(), theme_pop_dark(), theme_pop_minimal() – built-in themes
Converts count data to one row per icon. group_var and sum_var are
unquoted; high_group_var takes a character string for faceted charts.
df_plot <- process_data(
data = data.frame(sex = c("Female", "Male"), n = c(55, 45)),
group_var = sex,
sum_var = n,
sample_size = 20
)
Draws icon grids. Add an icon column, map icon and color in aes().
Do not map x or y.
ggplot() + geom_pop(data = df_plot, aes(icon = icon, color = type), size = 2) + scale_color_manual(values = c(Female = "#C0392B", Male = "#2980B9")) + theme_pop()
Drop-in replacement for geom_point() using Font Awesome icons.
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_icon_point(icon = "seedling", size = 1)
Search the bundled Font Awesome icon list by keyword.
fa_icons(query = "person")
Three built-in themes optimized for icon charts:
theme_pop(), theme_pop_dark(), theme_pop_minimal().
Maintainer: Jorge A. Roa-Contreras [email protected] (ORCID)
Authors:
Ralitza Soultanova [email protected] (ORCID)
Fernando Alarid-Escudero [email protected] (ORCID)
Carlos Pineda-Antunez [email protected] (ORCID)
Useful links:
library(ggplot2) library(dplyr) ## ------------------------------------------------------- ## geom_pop(): population icon grid ## ------------------------------------------------------- df_plot <- process_data( data = data.frame(sex = c("Female", "Male"), n = c(55, 45)), group_var = sex, sum_var = n, sample_size = 20 ) %>% mutate(icon = ifelse(type == "Female", "person-dress", "person")) ggplot() + geom_pop(data = df_plot, aes(icon = icon, color = type), size = 2) + scale_color_manual(values = c(Female = "#C0392B", Male = "#2980B9")) + theme_pop() + labs(title = "Population by sex", color = NULL) ## ------------------------------------------------------- ## geom_icon_point(): icon scatter plot ## ------------------------------------------------------- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_icon_point(icon = "seedling", size = 1) + scale_color_manual(values = c( setosa = "#43A047", versicolor = "#1E88E5", virginica = "#E53935" )) + labs(title = "Iris dataset", x = "Sepal Length", y = "Petal Length")library(ggplot2) library(dplyr) ## ------------------------------------------------------- ## geom_pop(): population icon grid ## ------------------------------------------------------- df_plot <- process_data( data = data.frame(sex = c("Female", "Male"), n = c(55, 45)), group_var = sex, sum_var = n, sample_size = 20 ) %>% mutate(icon = ifelse(type == "Female", "person-dress", "person")) ggplot() + geom_pop(data = df_plot, aes(icon = icon, color = type), size = 2) + scale_color_manual(values = c(Female = "#C0392B", Male = "#2980B9")) + theme_pop() + labs(title = "Population by sex", color = NULL) ## ------------------------------------------------------- ## geom_icon_point(): icon scatter plot ## ------------------------------------------------------- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_icon_point(icon = "seedling", size = 1) + scale_color_manual(values = c( setosa = "#43A047", versicolor = "#1E88E5", virginica = "#E53935" )) + labs(title = "Iris dataset", x = "Sepal Length", y = "Petal Length")
Retrieves Font Awesome icon names, optionally filtered by a search query or category. Results can be returned as a plain character vector or as a tibble with category classification.
fa_icons( query = NULL, category = NULL, regex = FALSE, classify = TRUE, include_unclassified = TRUE, class_map = NULL, primary_only = TRUE, as_vector = FALSE )fa_icons( query = NULL, category = NULL, regex = FALSE, classify = TRUE, include_unclassified = TRUE, class_map = NULL, primary_only = TRUE, as_vector = FALSE )
query |
Character string. Filter icons whose names contain |
category |
Character vector. One or more category names to filter by.
Run |
regex |
Logical. When |
classify |
Logical. When |
include_unclassified |
Logical. When |
class_map |
A named list mapping category names to regex patterns.
Defaults to the internal |
primary_only |
Logical. When |
as_vector |
Logical. When |
When as_vector = TRUE, a sorted character vector of icon names.
Otherwise a tibble with columns:
Icon name (character).
Primary category the icon belongs to, or NA
when unclassified (character).
All matching categories (list-column of character
vectors). Only present when primary_only = FALSE.
# All icons as a classified tibble fa_icons() # Quick lookup -- plain sorted vector head(fa_icons(as_vector = TRUE), 10) # Search for icons whose name contains "heart" fa_icons(query = "heart") # Filter by category fa_icons(category = "animals") # Regex search -- all icons starting with "arrow" fa_icons(query = "^arrow", regex = TRUE)# All icons as a classified tibble fa_icons() # Quick lookup -- plain sorted vector head(fa_icons(as_vector = TRUE), 10) # Search for icons whose name contains "heart" fa_icons(query = "heart") # Filter by category fa_icons(category = "animals") # Regex search -- all icons starting with "arrow" fa_icons(query = "^arrow", regex = TRUE)
df_coordinates_final DatasetDownloads and caches the df_coordinates_final dataset if it is not already cached locally.
This function ensures that the dataset is downloaded only once and loaded into memory
without cluttering the global environment. The dataset is stored in a package-specific
cache directory and retrieved efficiently for subsequent uses.
fetch_df_coordinates()fetch_df_coordinates()
The dataset is downloaded from GitHub
The file is cached in a directory specific to the package, which is determined
using R_user_dir. If the dataset is already cached, it will
be loaded directly from the cache instead of downloading again.
A data frame containing the df_coordinates_final dataset.
df <- fetch_df_coordinates() head(df)df <- fetch_df_coordinates() head(df)
Works exactly like geom_point(), but renders Font Awesome icons instead of dots. Pass any data with x and y variables - no special formatting required.
geom_icon_point( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, icon = NULL, size = 1, dpi = 50, legend_icons = TRUE, stroke_width = NULL, ... )geom_icon_point( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, icon = NULL, size = 1, dpi = 50, legend_icons = TRUE, stroke_width = NULL, ... )
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
|
na.rm |
logical, whether remove NA values |
show.legend |
Logical. Should this layer be included in the legends?
|
inherit.aes |
If |
icon |
Default Font Awesome icon (default: NULL). |
size |
Default icon size (default: 1). |
dpi |
Icon resolution (default: 50). |
legend_icons |
Show icons in legend (default: TRUE). |
stroke_width |
Numeric. Width of the icon outline/stroke. |
... |
additional parameters |
A ggplot layer.
geom_icon_point uses standard ggplot2 scatter plot aesthetics:
x - Numeric variable for x-axis
y - Numeric variable for y-axis
icon - Font Awesome icon name (optional, column or mapped)
color/colour - Color grouping
alpha - Transparency
size - Icon size
library(ggplot2) data <- data.frame( x = rnorm(20), y = rnorm(20), category = sample(c("A", "B", "C"), 20, replace = TRUE), icon = sample(c("heart", "star", "circle"), 20, replace = TRUE) ) # Map icon to a column ggplot(data, aes(x = x, y = y, icon = icon, color = category)) + geom_icon_point() # Use a fixed icon ggplot(data, aes(x = x, y = y, color = category)) + geom_icon_point(icon = "star")library(ggplot2) data <- data.frame( x = rnorm(20), y = rnorm(20), category = sample(c("A", "B", "C"), 20, replace = TRUE), icon = sample(c("heart", "star", "circle"), 20, replace = TRUE) ) # Map icon to a column ggplot(data, aes(x = x, y = y, icon = icon, color = category)) + geom_icon_point() # Use a fixed icon ggplot(data, aes(x = x, y = y, color = category)) + geom_icon_point(icon = "star")
Draws a circular representative population chart based on group proportions, where each point (person) represents a fixed number of individuals. Each person is rendered as a Font Awesome icon.
geom_pop( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, icon = "ggmale", group_var = NULL, sample_size = NULL, arrange = FALSE, seed = NULL, sum_var = NULL, facet = NULL, size = 1, dpi = 50, legend_icons = TRUE, stroke_width = NULL, ... )geom_pop( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, icon = "ggmale", group_var = NULL, sample_size = NULL, arrange = FALSE, seed = NULL, sum_var = NULL, facet = NULL, size = 1, dpi = 50, legend_icons = TRUE, stroke_width = NULL, ... )
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
|
na.rm |
logical, whether remove NA values |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
icon |
Default icon to use when no icon column is mapped. |
group_var |
(Deprecated) Use |
sample_size |
The total number of individuals (points) to draw. |
arrange |
Logical; if TRUE, output data is arranged by group. |
seed |
Optional numeric seed used only when |
sum_var |
Optional variable to sum over instead of counting. |
facet |
Optional faceting variable. If provided, final plot must be faceted
with ggplot2 (use |
size |
Icon size. If mapped in |
dpi |
Height (in pixels) of the rendered PNG when using
|
legend_icons |
Logical; if TRUE, legend displays the selected icons. |
stroke_width |
Numeric. Width of the icon outline in pixels (single value). |
... |
additional parameters |
A ggplot layer that renders a circular population chart with icons.
geom_pop understands the following aesthetics:
icon: Font Awesome icon name (mapped column)
group: grouping variable for raw data mode
color/colour: icon color
alpha: transparency (must be mapped)
size: icon size (mapped or fixed)
geom_icon_point, process_data,
geom_image
library(ggplot2) df <- data.frame( sex = rep(c("F", "M"), each = 10), icon = rep(c("female", "male"), each = 10) ) ggplot() + geom_pop( data = df, aes(icon = icon, group = sex, color = sex), size = 3, dpi = 80 )library(ggplot2) df <- data.frame( sex = rep(c("F", "M"), each = 10), icon = rep(c("female", "male"), each = 10) ) ggplot() + geom_pop( data = df, aes(icon = icon, group = sex, color = sex), size = 3, dpi = 80 )
The process_data function processes a dataset to calculate group proportions and generates a sampled dataset based on specified parameters. This processed data is suitable for creating visual representations, such as population charts, where each sample represents a group with associated counts and proportions.
process_data( data, high_group_var = NULL, group_var, sum_var = NULL, sample_size = 100 )process_data( data, high_group_var = NULL, group_var, sum_var = NULL, sample_size = 100 )
data |
A data frame containing the population data to be processed. |
high_group_var |
Character vector, optional. The variables used to group individuals hierarchically. This should be a categorical variable. If provided, the function samples individuals within each group defined by these variables. |
group_var |
Quosure. The variable used to group individuals in the dataset. This should be a categorical variable. |
sum_var |
Quosure, optional. The variable to sum over within each group. If |
sample_size |
Integer. The total number of individuals to sample based on group proportions. Must be a positive integer. |
A tibble (data frame) with the following columns:
The sampled group type.
The group identifier.
The count of individuals in the group.
The proportion of the group relative to the total population.
A convenience function to set appropriate legend key sizes for icon-based legends. This is equivalent to using theme(legend.key.size = ...) but provides sensible defaults for population icon plots.
scale_legend_icon( size = 10, unit = "mm", spacing = 0.2, size_multiplier = 2, ... )scale_legend_icon( size = 10, unit = "mm", spacing = 0.2, size_multiplier = 2, ... )
size |
Numeric. Legend key size in specified units (default 10). |
unit |
Character. Unit for legend key sizing (default "mm"). |
spacing |
Numeric. Spacing between legend items as fraction of size (default 0.2). |
size_multiplier |
Numeric. Multiplier to apply to the size for spacing calculations (default 2). |
... |
Additional theme arguments. |
A ggplot2 theme object that can be added to a plot.
library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(df, aes(icon = icon, color = type)) + geom_pop() + scale_legend_icon(size = 20)library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(df, aes(icon = icon, color = type)) + geom_pop() + scale_legend_icon(size = 20)
A minimal theme optimized for icon-based population plots. Similar to
theme_void() but with automatic legend key sizing, appropriate margins,
and sensible defaults for population visualizations.
theme_pop( base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22, legend_icon_size = NULL, legend_spacing = NULL, plot_margin = NULL, legend_position = "right" )theme_pop( base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22, legend_icon_size = NULL, legend_spacing = NULL, plot_margin = NULL, legend_position = "right" )
base_size |
Base font size in points (default: 11). |
base_family |
Base font family (default: ""). |
base_line_size |
Base size for line elements (default: base_size/22). |
base_rect_size |
Base size for rect elements (default: base_size/22). |
legend_icon_size |
Size of legend icons in cm. If NULL (default), automatically calculated as base_size/20 for proportional sizing. |
legend_spacing |
Spacing between legend items in cm (default: 0.3 * legend_icon_size). |
plot_margin |
Plot margins. Default: margin(5.5, 5.5, 5.5, 5.5, "pt"). Can be a single numeric (applied to all sides) or margin() object. |
legend_position |
Position of legend: "none", "left", "right", "bottom", "top" (default: "right"). |
A ggplot2 theme object.
library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(data = df, aes(icon = icon, color = type)) + geom_pop(size = 1) + theme_pop()library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(data = df, aes(icon = icon, color = type)) + geom_pop(size = 1) + theme_pop()
A dark variant of theme_pop() with white text on black background. Perfect for presentations or dark-mode visualizations.
theme_pop_dark( base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22, legend_icon_size = NULL, legend_spacing = NULL, plot_margin = NULL, legend_position = "right", bg_color = "black", text_color = "white" )theme_pop_dark( base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22, legend_icon_size = NULL, legend_spacing = NULL, plot_margin = NULL, legend_position = "right", bg_color = "black", text_color = "white" )
base_size |
Base font size in points (default: 11). |
base_family |
Base font family (default: ""). |
base_line_size |
Base size for line elements (default: base_size/22). |
base_rect_size |
Base size for rect elements (default: base_size/22). |
legend_icon_size |
Size of legend icons in cm. If NULL (default), automatically calculated as base_size/20 for proportional sizing. |
legend_spacing |
Spacing between legend items in cm (default: 0.3 * legend_icon_size). |
plot_margin |
Plot margins. Default: margin(5.5, 5.5, 5.5, 5.5, "pt"). Can be a single numeric (applied to all sides) or margin() object. |
legend_position |
Position of legend: "none", "left", "right", "bottom", "top" (default: "right"). |
bg_color |
Background color (default: "black"). |
text_color |
Text color (default: "white"). |
A ggplot2 theme object.
library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(data = df, aes(icon = icon, color = type)) + geom_pop(size = 1) + theme_pop_dark(base_size = 40)library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(data = df, aes(icon = icon, color = type)) + geom_pop(size = 1) + theme_pop_dark(base_size = 40)
An ultra-minimal variant with no margins or legend, perfect for icon arrays without annotations.
theme_pop_minimal(base_size = 11, base_family = "")theme_pop_minimal(base_size = 11, base_family = "")
base_size |
Base font size in points (default: 11). |
base_family |
Base font family (default: ""). |
A ggplot2 theme object.
library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(data = df, aes(icon = icon, color = type)) + geom_pop(size = 1) + theme_pop_minimal()library(ggplot2) df <- data.frame( type = rep(c("A", "B"), each = 10), icon = rep(c("circle", "square"), each = 10) ) ggplot(data = df, aes(icon = icon, color = type)) + geom_pop(size = 1) + theme_pop_minimal()