| Title: | Brazilian Soccer Badges Plots in 'ggplot2' |
|---|---|
| Description: | A set of functions to visualize Brazilian Soccer analysis in 'ggplot2'. |
| Authors: | Bruno Mioto [cre, aut], Gabriela Junqueira [aut] |
| Maintainer: | Bruno Mioto <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-06-03 09:48:57 UTC |
| Source: | https://github.com/brunomioto/futebolplotR |
This function standardizes Brazilian Soccer team abbreviations to brasileirao defaults.
clean_team_abbrs(abbr, keep_non_matches = TRUE)clean_team_abbrs(abbr, keep_non_matches = TRUE)
abbr |
a character vector of abbreviations |
keep_non_matches |
If |
A character vector with the length of abbr and cleaned team abbreviations
if they are included in team_abbr_mapping.
Non matches may be replaced with NA (depending on the value of keep_non_matches).
In conjunction with the ggplot2::theme system, the following element_
functions enable images in non-data components of the plot, e.g. axis text.
element_futebol_badge(): draws Brazilian Soccer team badges instead of their abbreviations.
element_futebol_badge( alpha = NULL, colour = NA, hjust = NULL, vjust = NULL, color = NULL, size = 0.5 )element_futebol_badge( alpha = NULL, colour = NA, hjust = NULL, vjust = NULL, color = NULL, size = 0.5 )
alpha |
The alpha channel, i.e. transparency level, as a numerical value between 0 and 1. |
colour, color
|
The image will be colorized with this color. Use the
special character |
hjust, vjust
|
The horizontal and vertical adjustment respectively. Must be a numerical value between 0 and 1. |
size |
The output grob size in |
The elements translate Brazilian Soccer team abbreviations into badge images.
An S3 object of class element.
geom_futebol_badges(), and ggpath::element_path()
for more information on valid team abbreviations, and other parameters.
library(futebolplotR) library(ggplot2) team_abbr <- valid_team_names() df <- data.frame( random_value = runif(length(team_abbr), 0, 1), team = team_abbr ) # use badges for x-axis ggplot(df, aes(x = team, y = random_value)) + geom_col(aes(color = team, fill = team), width = 0.5) + scale_color_futebol(type = "secondary") + scale_fill_futebol(alpha = 0.4) + theme_minimal() + theme(axis.text.x = element_futebol_badge()) # use badges for y-axis ggplot(df, aes(y = team, x = random_value)) + geom_col(aes(color = team, fill = team), width = 0.5) + scale_color_futebol(type = "secondary") + scale_fill_futebol(alpha = 0.4) + theme_minimal() + theme(axis.text.y = element_futebol_badge())library(futebolplotR) library(ggplot2) team_abbr <- valid_team_names() df <- data.frame( random_value = runif(length(team_abbr), 0, 1), team = team_abbr ) # use badges for x-axis ggplot(df, aes(x = team, y = random_value)) + geom_col(aes(color = team, fill = team), width = 0.5) + scale_color_futebol(type = "secondary") + scale_fill_futebol(alpha = 0.4) + theme_minimal() + theme(axis.text.x = element_futebol_badge()) # use badges for y-axis ggplot(df, aes(y = team, x = random_value)) + geom_col(aes(color = team, fill = team), width = 0.5) + scale_color_futebol(type = "secondary") + scale_fill_futebol(alpha = 0.4) + theme_minimal() + theme(axis.text.y = element_futebol_badge())
This geom is used to plot Brazilian soccer team badges instead
of points in a ggplot. It requires x, y aesthetics as well as a valid Brazilian soccer
team abbreviation. The latter can be checked with valid_team_names().
geom_futebol_badges( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE )geom_futebol_badges( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = FALSE, 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 |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
A ggplot2 layer (ggplot2::layer()) that can be added to a plot
created with ggplot2::ggplot().
geom_futebol_badges() understands the following aesthetics (required aesthetics are in bold):
x - The x-coordinate.
y - The y-coordinate.
team_abbr - The team abbreviation. Should be one of valid_team_names(). The function tries to clean team names internally by calling clean_team_abbrs().
alpha = NULL - The alpha channel, i.e. transparency level, as a numerical value between 0 and 1.
colour = NULL - The image will be colorized with this colour. Use the special character "b/w" to set it to black and white. For more information on valid colour names in ggplot2 see https://ggplot2.tidyverse.org/articles/ggplot2-specs.html?q=colour#colour-and-fill
angle = 0 - The angle of the image as a numerical value between 0° and 360°.
hjust = 0.5 - The horizontal adjustment relative to the given x coordinate. Must be a numerical value between 0 and 1.
vjust = 0.5 - The vertical adjustment relative to the given y coordinate. Must be a numerical value between 0 and 1.
width = 1.0 - The desired width of the image in npc (Normalised Parent Coordinates).
The default value is set to 1.0 which is big but it is necessary
because all used values are computed relative to the default.
A typical size is width = 0.075 (see below examples).
height = 1.0 - The desired height of the image in npc (Normalised Parent Coordinates).
The default value is set to 1.0 which is big but it is necessary
because all used values are computed relative to the default.
A typical size is height = 0.1 (see below examples).
library(futebolplotR) library(ggplot2) team_abbr <- futebolplotR::valid_team_names() df <- data.frame( a = rep(1:5, 2), b = sort(rep(1:2, 5), decreasing = TRUE), teams = team_abbr[1:10] ) # keep alpha == 1 for all teams including an "A" matches <- grepl("A", team_abbr[1:10]) df$alpha <- ifelse(matches, 1, 0.2) # also set a custom fill colour for the non "A" teams df$colour <- ifelse(matches, NA, "gray") # scatterplot of all badges ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams), width = 0.075) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + theme_void() # apply alpha via an aesthetic from inside the dataset `df` # please note that you have to add scale_alpha_identity() to use the alpha # values in your dataset! ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams, alpha = alpha), width = 0.075) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + scale_alpha_identity() + theme_void() # apply alpha and colour via an aesthetic from inside the dataset `df` # please note that you have to add scale_alpha_identity() as well as # scale_color_identity() to use the alpha and colour values in your dataset! ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams, alpha = alpha, colour = colour), width = 0.075) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + scale_alpha_identity() + scale_color_identity() + theme_void() # apply alpha as constant for all badges ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams), width = 0.075, alpha = 0.6) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + theme_void()library(futebolplotR) library(ggplot2) team_abbr <- futebolplotR::valid_team_names() df <- data.frame( a = rep(1:5, 2), b = sort(rep(1:2, 5), decreasing = TRUE), teams = team_abbr[1:10] ) # keep alpha == 1 for all teams including an "A" matches <- grepl("A", team_abbr[1:10]) df$alpha <- ifelse(matches, 1, 0.2) # also set a custom fill colour for the non "A" teams df$colour <- ifelse(matches, NA, "gray") # scatterplot of all badges ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams), width = 0.075) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + theme_void() # apply alpha via an aesthetic from inside the dataset `df` # please note that you have to add scale_alpha_identity() to use the alpha # values in your dataset! ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams, alpha = alpha), width = 0.075) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + scale_alpha_identity() + theme_void() # apply alpha and colour via an aesthetic from inside the dataset `df` # please note that you have to add scale_alpha_identity() as well as # scale_color_identity() to use the alpha and colour values in your dataset! ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams, alpha = alpha, colour = colour), width = 0.075) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + scale_alpha_identity() + scale_color_identity() + theme_void() # apply alpha as constant for all badges ggplot(df, aes(x = a, y = b)) + geom_futebol_badges(aes(team_abbr = teams), width = 0.075, alpha = 0.6) + geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) + theme_void()
These functions map soccer team names to their team colors in color and fill aesthetics
scale_color_futebol( type = c("primary", "secondary"), values = NULL, ..., aesthetics = "colour", breaks = ggplot2::waiver(), na.value = "grey50", guide = NULL, alpha = NA ) scale_colour_futebol( type = c("primary", "secondary"), values = NULL, ..., aesthetics = "colour", breaks = ggplot2::waiver(), na.value = "grey50", guide = NULL, alpha = NA ) scale_fill_futebol( type = c("primary", "secondary"), values = NULL, ..., aesthetics = "fill", breaks = ggplot2::waiver(), na.value = "grey50", guide = NULL, alpha = NA )scale_color_futebol( type = c("primary", "secondary"), values = NULL, ..., aesthetics = "colour", breaks = ggplot2::waiver(), na.value = "grey50", guide = NULL, alpha = NA ) scale_colour_futebol( type = c("primary", "secondary"), values = NULL, ..., aesthetics = "colour", breaks = ggplot2::waiver(), na.value = "grey50", guide = NULL, alpha = NA ) scale_fill_futebol( type = c("primary", "secondary"), values = NULL, ..., aesthetics = "fill", breaks = ggplot2::waiver(), na.value = "grey50", guide = NULL, alpha = NA )
type |
One of |
values |
If |
... |
Arguments passed on to
|
aesthetics |
Character string or vector of character strings listing the
name(s) of the aesthetic(s) that this scale works with. This can be useful, for
example, to apply colour settings to the |
breaks |
One of:
|
na.value |
The aesthetic value to use for missing ( |
guide |
A function used to create a guide or its name. If |
alpha |
Factor to modify color transparency via a call to |
The theme elements element_futebol_badge() to
replace axis text labels with badges.
library(futebolplotR) library(ggplot2) team_abbr <- valid_team_names() df <- data.frame( random_value = runif(length(team_abbr), 0, 1), teams = team_abbr ) ggplot(df, aes(x = teams, y = random_value)) + geom_col(aes(color = teams, fill = teams), width = 0.5) + scale_color_futebol(type = "secondary") + scale_fill_futebol(alpha = 0.4) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1))library(futebolplotR) library(ggplot2) team_abbr <- valid_team_names() df <- data.frame( random_value = runif(length(team_abbr), 0, 1), teams = team_abbr ) ggplot(df, aes(x = teams, y = random_value)) + geom_col(aes(color = teams, fill = teams), width = 0.5) + scale_color_futebol(type = "secondary") + scale_fill_futebol(alpha = 0.4) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1))
Output Valid Brazilian Soccer Team Abbreviations
valid_team_names()valid_team_names()
A vector of type "character".
# List valid Brazilian soccer team abbreviations valid_team_names()# List valid Brazilian soccer team abbreviations valid_team_names()