The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Package {ipeaplot}


Type: Package
Title: Add Ipea Editorial Standards to 'ggplot2' Graphics
Version: 1.0.0
Maintainer: Pedro Ferreira <pedro.ferreira2@ipea.gov.br>
Description: Convenient functions to create 'ggplot2' graphics following the editorial guidelines of the Institute for Applied Economic Research (Ipea).
License: MIT + file LICENSE
URL: https://github.com/ipeadata-lab/ipeaplot
BugReports: https://github.com/ipeadata-lab/ipeaplot/issues
Depends: R (≥ 3.3.2)
Imports: checkmate, ggplot2, grDevices, paletteer, scales, rlang, ggthemes, svglite, ragg
Suggests: abjData, data.table, dplyr, forcats, knitr, patchwork, purrr, reshape, rmarkdown, sf, sysfonts, testthat (≥ 3.0.0), tidyr, withr
VignetteBuilder: knitr
Encoding: UTF-8
Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-08-31 09:24:56 UTC; cavalcanti1985
Author: Pedro Ferreira [aut, cre], Pedro Jorge [aut], Daniel Lima [aut], Gustavo Coelho [aut], Rafael H. M. Pereira [aut], Lucas Mation [aut], Fabio Vaz [ctb], Ipea - Institue for Applied Economic Research [cph, fnd]
Repository: CRAN
Date/Publication: 2026-08-31 17:00:22 UTC

ipeaplot: ggplot Graphics in Ipea Standard

Description

Convenient functions to create ggplot graphics following the editorial guidelines of the Institute for Applied Economic Research - Ipea.

Usage

Please check the vignettes and data documentation on the website.

Author(s)

Maintainer: Pedro Ferreira pedro.ferreira2@ipea.gov.br

Authors:

Other contributors:

See Also

Useful links:


Contrasting text colour for labels drawn over a fill colour

Description

Given one or more fill/background colours, returns "white" or "black", whichever gives better contrast against that background. Useful for value labels drawn inside bars or over points/lines, matching the Ipea editorial guidelines for graphics, which alternate the colour of data labels according to how dark the colour behind them is. See https://www.ipea.gov.br/manualeditorial/padroes/padroes-grafico-visuais/ilustracoes-pi.html.

Usage

ipea_contrast_color(background)

Arguments

background

A character vector of colours (hex codes or R colour names) used as the fill/background behind the label.

Value

A character vector the same length as background, containing "white" or "black".

See Also

Other ggplot2 theme functions: ipea_label_size(), scale_color_ipea(), scale_fill_ipea(), theme_ipea()

Examples

ipea_contrast_color(c("#29112F", "#D2A0C9"))

library(ggplot2)
df <- data.frame(grupo = c("A", "B"), valor = c(22.6, 4.7),
                  cor = c("#29112F", "#D2A0C9"))
ggplot(df, aes(grupo, valor, fill = cor, label = valor)) +
  geom_col() +
  geom_text(aes(color = ipea_contrast_color(cor)), size = ipea_label_size(),
            fontface = "bold") +
  scale_fill_identity() +
  scale_color_identity() +
  theme_ipea()

Font size for data labels in Ipea graphics

Description

Converts a font size in points (pt) into the size argument/aesthetic (in mm) expected by ggplot2::geom_text(), ggplot2::geom_label() and similar geoms. ggplot2 specifies text size for geoms in mm and internally converts it to points by multiplying by 2.845276 (72.27/25.4); this helper performs the inverse conversion so that labels are rendered at an exact point size.

Usage

ipea_label_size(pt = 6)

Arguments

pt

Numeric. Desired font size in points. Defaults to 6, the size used by the editorial guidelines of the Institute for Applied Economic Research (Ipea) for labels drawn over data (e.g. values on bars or lines). See https://www.ipea.gov.br/manualeditorial/padroes/padroes-grafico-visuais/ilustracoes-pi.html.

Value

A numeric value (in mm) to be passed to the size argument/aesthetic of ggplot2::geom_text(), ggplot2::geom_label() or similar geoms.

See Also

Other ggplot2 theme functions: ipea_contrast_color(), scale_color_ipea(), scale_fill_ipea(), theme_ipea()

Examples

library(ggplot2)
ggplot(mtcars[1:5, ], aes(hp, mpg, label = round(mpg))) +
  geom_text(size = ipea_label_size(), colour = "black") +
  theme_ipea()

Ipea palette

Description

Ipea palette

Usage

ipea_pal(
  palette = c("Blue", "Green", "Orange", "Pink", "Pink-Deep", "Green-Blue",
    "Green-Blue-White", "Red-Blue", "Red-Blue-White", "Orange-Blue", "Orange-Blue-White",
    "Viridis", "Inferno", "Magma", "Plasma", "Cividis", "NT", "NT-Categorical", "TD",
    "TD-Categorical"),
  alpha = 1,
  begin = 0,
  end = 1,
  palette_direction = 1
)

Arguments

palette

A character string indicating the color map option to use. These options are available: 'Blue', 'Green', 'Orange', 'Pink', 'Pink-Deep', 'Red-Blue' 'Orange-Blue', 'Green-Blue', 'Viridis', 'Inferno', 'Magma', 'Plasma' 'Cividis', 'NT', 'NT-Categorical', 'TD', 'TD-Categorical'.

alpha

The alpha transparency in a number between 0 and 1.

begin

The (corrected) hue in a number between 0 and 1 at which the color map begins.

end

The (corrected) hue in a number between 0 and 1 at which the color map ends.

palette_direction

Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.

Value

ipea_palette produces a character vector, cv, containing color hex codes. This vector can be utilized to establish a custom color scheme for future graphics using palette(cv), or it can be applied directly as a col = parameter in graphic functions or within par.

References

'Blue','Green','Orange','Pink','Pink-Deep','Green-Blue','Green-Blue-White','Red-Blue','Red-Blue-White', 'Orange-Blue','Orange-Blue-White', 'Viridis','Inferno', 'Magma','Plasma' and 'Cividis': https://pmassicotte.github.io/paletteer_gallery/ 'NT'/'TD' and their '-Categorical' variants: see ipea_palette().

Examples

scales::show_col(ipea_pal()(10))
scales::show_col(ipea_pal(palette_direction = -1)(6))
scales::show_col(ipea_pal(begin = 0.2, end = 0.8)(4))
scales::show_col(ipea_pal(palette = "Green")(6))
scales::show_col(ipea_pal(palette = "NT")(10))
scales::show_col(ipea_pal(palette = "TD-Categorical")(12))

Ipea Color Palette and Scales

Description

This function creates a vector of n equally spaced colors along the selected color map.

Usage

ipea_palette(
  palette = c("Blue", "Green", "Orange", "Pink", "Pink-Deep", "Green-Blue",
    "Green-Blue-White", "Red-Blue", "Red-Blue-White", "Orange-Blue", "Orange-Blue-White",
    "Viridis", "Inferno", "Magma", "Plasma", "Cividis", "NT", "NT-Categorical", "TD",
    "TD-Categorical"),
  n,
  alpha = 1,
  begin = 0,
  end = 1,
  palette_direction = 1
)

Arguments

palette

A character string indicating the color map option to use. These options are available:'Blue', 'Green', 'Orange', 'Pink', 'Pink-Deep', 'Red-Blue' 'Orange-Blue', 'Green-Blue', 'Red-Blue-White', 'Orange-Blue-White', 'Green-Blue-White', 'Viridis', 'Inferno', 'Magma', 'Plasma', 'Cividis', 'NT', 'NT-Categorical', 'TD', 'TD-Categorical'.

n

The number of colors (\ge 1) used in the palette.

alpha

The alpha transparency in a number between 0 and 1.

begin

The (corrected) hue in a number between 0 and 1 at which the color map begins.

end

The (corrected) hue in a number between 0 and 1 at which the color map ends.

palette_direction

Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.

Details

A 9-color Ipea palette.

Value

ipea_palette produces a character vector, cv, containing color hex codes. This vector can be utilized to establish a custom color scheme for future graphics using palette(cv), or it can be applied directly as a col = parameter in graphic functions or within par.

References

'Blue','Green','Orange','Pink','Pink-Deep','Green-Blue','Green-Blue-White','Red-Blue','Red-Blue-White', 'Orange-Blue','Orange-Blue-White', 'Viridis','Inferno', 'Magma','Plasma' and 'Cividis': https://pmassicotte.github.io/paletteer_gallery/ 'NT' and 'TD' are sequential palettes taken from the cover, section-title and chart colours of two Ipea editorial series (Nota Tecnica and Texto para Discussao, respectively). 'NT-Categorical' and 'TD-Categorical' are qualitative 12-colour sets built from the same two publications, interleaving 6 shades of each of their two hues so that adjacent categories stay visually distinct. scale_color_ipea()/scale_fill_ipea() switch automatically from 'NT'/'TD' to their '-Categorical' variant when the mapped variable is discrete, so most users never need to type the '-Categorical' suffix themselves.


Save ggplot in multiple formats

Description

Unified function to save ggplot objects in one or more formats.

Usage

save_ipeaplot(
  gplot = ggplot2::last_plot(),
  file.name,
  format = NULL,
  width = 6.3,
  height = 3.94,
  units = c("in", "mm", "cm", "px"),
  dpi = 300,
  background = "white",
  quality = 95,
  path = ".",
  scale = 1,
  overwrite = TRUE,
  include_date = FALSE,
  date_format = "%Y%m%d",
  use_cairo = TRUE,
  use_ragg = TRUE,
  quiet = TRUE,
  ...
)

Arguments

gplot

ggplot object. Default: ggplot2::last_plot().

file.name

Base name of the file (without extension). E.g., "results/figs/my_plot".

format

Vector with one or more of: "eps", "jpg", "pdf", "png", "svg". If NULL, uses getOption("ipea.plot.default_format", "eps").

width, height

Plot dimensions (default 160 x 100).

units

Units: "mm", "cm", "in", "px" (default "in").

dpi

DPI for raster formats (default 300).

background

Background color; use NA for transparent PNGs. For JPEG (no transparency), NA becomes "white".

quality

JPEG quality (0 to 100) (default 95).

path

Output directory (default ".").

scale

Scale factor passed to ggsave (default 1).

overwrite

If FALSE, does not overwrite existing files: creates suffixes _1, _2, ... (default TRUE).

include_date

If TRUE, appends the date to the file name: _YYYYMMDD (default FALSE).

date_format

Date format (default "%Y%m%d").

use_cairo

Prefer using Cairo for PDF/EPS (default TRUE).

use_ragg

Prefer using ragg for PNG/JPG when available (default TRUE).

quiet

Suppress messages from ggsave when supported (default TRUE).

...

Passed to ggplot2::ggsave() (and therefore to the underlying graphics devices when applicable).

Value

Named (invisible) vector with the paths of the saved files.


Scale color IPEA

Description

Generate a color palette (continuous or discrete) following the editorial guidelines used by the Institute for Applied Economic Research - Ipea.

Usage

scale_color_ipea(
  palette = c("Blue", "Green", "Orange", "Pink", "Pink-Deep", "Green-Blue",
    "Green-Blue-White", "Red-Blue", "Red-Blue-White", "Orange-Blue", "Orange-Blue-White",
    "Viridis", "Inferno", "Magma", "Plasma", "Cividis", "NT", "NT-Categorical", "TD",
    "TD-Categorical"),
  palette_direction = 1,
  decimal.mark = ",",
  barheight = NULL,
  barwidth = NULL,
  title.hjust = NULL,
  label.hjust = NULL,
  ...
)

Arguments

palette

A character vector specifying the available palette for the color palette. The default palette are "Blue", but we can also change to 'Green', 'Orange', 'Pink', 'Pink-Deep', 'Red-Blue', 'Orange-Blue', 'Green-Blue', 'Red-Blue-White', 'Orange-Blue-White', 'Green-Blue-White', 'Viridis', 'Inferno', 'Magma', 'Plasma', 'Cividis', 'NT', 'TD'. 'NT' and 'TD' automatically switch from their sequential (continuous) colours to a 12-colour qualitative set when the mapped variable is discrete – there is no need to request 'NT-Categorical'/'TD-Categorical' directly, though those names remain available for ipea_pal()/ipea_palette().

palette_direction

A logical argument specifying if the ordering of the colors will follow the default of the palette (when the argument is 1) or if it will have an inverted ordering (for cases where it is -1).

decimal.mark

The character to be used to indicate the numeric decimal point and Character used between every 3 digits to separate thousands. By default, the function uses a comma ",", following the format used in Brazilian Portuguese.

barheight

The height of the color gradient bar. This parameter is used when the direction is set to "horizontal".

barwidth

The width of the color gradient bar. This parameter is used when the direction is set to "horizontal".

title.hjust

A number specifying horizontal justification of the title text.

label.hjust

A number specifying vertical justification of the title text.

...

Additional arguments to be passed to the scale_fill_gradientn, scale_color_gradientn, scale_fill_distiller or scale_color_distiller function from the ggplot2 package.

Value

A list object be added to a ggplot object to change color pallete.

See Also

Other ggplot2 theme functions: ipea_contrast_color(), ipea_label_size(), scale_fill_ipea(), theme_ipea()

Examples

# Creating scale for ggplot2 graph using default arguments
library(ggplot2)
fig_raw <- ggplot() +
  geom_point(data = mtcars, aes(x = hp , y = mpg, color = cyl)) +
  scale_color_ipea()

# Creating scale for ggplot2 graph using green sequential palette
fig_raw <- ggplot() +
  geom_point(data = mtcars, aes(x = hp , y = mpg, color = cyl)) +
  scale_color_ipea(palette = "Green")

# "NT" uses the sequential magenta ramp for a numeric variable, and the
# 12-colour qualitative set for a discrete one, automatically
fig_raw <- ggplot() +
  geom_point(data = mtcars, aes(x = hp , y = mpg, color = factor(cyl))) +
  scale_color_ipea(palette = "NT")

Scale fill IPEA

Description

Generate a fill palette (continuous or discrete) in the formatting of texts published by the Institute for Applied Economic Research (IPEA)

Usage

scale_fill_ipea(
  palette = c("Blue", "Green", "Orange", "Pink", "Pink-Deep", "Green-Blue",
    "Green-Blue-White", "Red-Blue", "Red-Blue-White", "Orange-Blue", "Orange-Blue-White",
    "Viridis", "Inferno", "Magma", "Plasma", "Cividis", "NT", "NT-Categorical", "TD",
    "TD-Categorical"),
  palette_direction = 1,
  decimal.mark = ",",
  barheight = NULL,
  barwidth = NULL,
  title.hjust = NULL,
  label.hjust = NULL,
  ...
)

Arguments

palette

A character vector specifying the available palette for the color palette. The default palette are "Blue", but we can also change to 'Green', 'Orange', 'Pink', 'Pink-Deep', 'Red-Blue', 'Orange-Blue', 'Green-Blue', 'Red-Blue-White', 'Orange-Blue-White', 'Green-Blue-White', 'Viridis', 'Inferno', 'Magma', 'Plasma', 'Cividis', 'NT', 'TD'. 'NT' and 'TD' automatically switch from their sequential (continuous) colours to a 12-colour qualitative set when the mapped variable is discrete – there is no need to request 'NT-Categorical'/'TD-Categorical' directly, though those names remain available for ipea_pal()/ipea_palette().

palette_direction

A logical argument specifying if the ordering of the colors will follow the default of the palette (when the argument is 1) or if it will have an inverted ordering (for cases where it is 0).

decimal.mark

The character to be used to indicate the numeric decimal point and Character used between every 3 digits to separate thousands. By default, the function uses a comma ",", following the format used in Brazilian Portuguese.

barheight

The height of the color gradient bar. This parameter is used when the direction is set to "horizontal".

barwidth

The width of the color gradient bar. This parameter is used when the direction is set to "horizontal".

title.hjust

A number specifying horizontal justification of the title text.

label.hjust

A number specifying vertical justification of the title text.

...

Additional arguments to be passed to the scale_fill_gradientn, scale_color_gradientn, scale_fill_distiller or scale_color_distiller function from the ggplot2 package

Value

A list object be added to a ggplot object to change color pallete.

See Also

Other ggplot2 theme functions: ipea_contrast_color(), ipea_label_size(), scale_color_ipea(), theme_ipea()

Examples

# Creating scale for ggplot2 graph using default arguments
library(ggplot2)
fig_raw <- ggplot() +
  geom_col(data = mtcars, aes(x = hp , y = mpg, fill = cyl)) +
  scale_fill_ipea()

# Creating scale for ggplot2 graph using green sequential palette
fig_raw <- ggplot() +
  geom_col(data = mtcars, aes(x = hp , y = mpg, fill = cyl)) +
  scale_fill_ipea(palette = "Green")

# "TD" uses the sequential blue ramp for a numeric variable, and the
# 12-colour qualitative set for a discrete one, automatically
fig_raw <- ggplot() +
  geom_col(data = mtcars, aes(x = hp , y = mpg, fill = factor(cyl))) +
  scale_fill_ipea(palette = "TD")

Ggplot theme for Ipea charts and figures

Description

Applies a custom theme for ggplot figures following the editorial guidelines used by the Institute for Applied Economic Research - Ipea. The function includes standardized formatting of options for axis lines, text,

Usage

theme_ipea(
  axis_lines = "full",
  axis_values = TRUE,
  legend.position = "bottom",
  grid.adjust = "horizontal",
  x_breaks = NULL,
  y_breaks = NULL,
  expand_x_limit = TRUE,
  expand_y_limit = TRUE,
  x_text_angle = 0,
  include_x_text_title = TRUE,
  include_y_text_title = TRUE,
  include_ticks = TRUE,
  ...
)

Arguments

axis_lines

A character vector specifying the axis style. Valid options are "none" (no axis lines), "full" (full-length axis lines), and "half" (half-length axis lines), the default.

axis_values

Logical value indicating whether to show text elements. If TRUE, axis text will be displayed in black; otherwise, they will be hidden.

legend.position

A character vector specifying the position of the legend. Valid options are "bottom" (default, matching the Ipea editorial guidelines), "right", "left", and "top".

grid.adjust

Defines whether the grid lines should be "horizontal" (default) or "vertical".

x_breaks

Numeric. The number of breaks on the x-axis

y_breaks

Numeric. The number of breaks on the y-axis

expand_x_limit

Logical value that indicates whether the x-axis boundary should be expanded. If TRUE, the x-axis limits will be expanded; otherwise there will be no change

expand_y_limit

Logical value that indicates whether the y-axis boundary should be expanded. If TRUE, the x-axis limits will be expanded; otherwise there will be no change

x_text_angle

Numeric. Angle in degrees of the text in the x-axis.

include_x_text_title

Logical. Whether to include x text title Defaults to TRUE.

include_y_text_title

Logical. Whether to include x text title. Defaults to TRUE.

include_ticks

Logical. Whether to include ticks. Defaults to TRUE.

...

Additional arguments to be passed to the theme function from the ggplot2 package.

Value

A custom theme for IPEA graphics.

See Also

Other ggplot2 theme functions: ipea_contrast_color(), ipea_label_size(), scale_color_ipea(), scale_fill_ipea()

Examples

# Creating theme for ggplot2 graph using default arguments
library(ggplot2)
fig_raw <- ggplot() +
  geom_col(data = mtcars, aes(x = hp , y = mpg, fill = cyl)) +
  theme_ipea()

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.