Creates an area plot with two categories (cat1
and cat2
) over
the values of an order
variable. They are shown in terms of percentage
and their sum is 100%. The values of the categories are associated with the
horizontal axis. Their areas are stacked horizontally. The rightmost category
(in red) has its values highlighted in the vertical axis on the right. The
order variable is shown in the vertical axis and is labeled in the left. Both
axes are inverted. A bounded random walk effect can be added to the left of
the area (like the plot had been torn) as function of some parameters
(seed
, res_step
and limits
). Furthermore, there is three
slots for text (title
, subtitle
and message
)
Arguments
- data
data-frame class object: the data to be shown in the area plot. Each row must contain the value of each of the two categories as well one instance of the order variable.
- order
character: the name of the order variable.
- cat1
character: the name of the leftmost category (in red). Its values are highlighted in the vertical axis.
- cat2
character: the name of the rightmost category (in black).
- dpi
integer: resolution of the rendered texts and image.
- seed
integer: seed used for calculate the bounded random walk.
- res_step
numeric: the product of
res_step
and the numeric range of the order variable defines the step size of the bounded random walk.- limits
numeric vector: the lower and superior limits that bound the random walk. Must be given in that order: (lower, superior).
- names
character vector: the names of the categories. shown in the first areas in the superior part of the plot and in the vertical axis title in the left.
- title
character: text on the top of the plot
- subtitle
character: text under the title
- message
character: text on the bottom of the plot. has a brown background.
- path
character: path to save the image of the plot.
- filename
character: name of the image and its extension.
Examples
library(dubois)
data <- dubois::managers %>%
dplyr::select(race, year, pct_bosses_total) %>%
tidyr::pivot_wider(
names_from = "race",
values_from = "pct_bosses_total"
)
title <- "PARTICIPATION IN MANAGERIAL POSITIONS BY RACE IN BRAZIL."
subtitle <- "INSPIRED BY: W.E.B. DU BOIS | DATA FROM: IBGE | GRAPHIC BY: ICARO BERNARDES"
message <- "IN THE SERIES, USUALLY WHITES OCCUPY SLIGHTLY LESS GENERAL WORK POSITIONS. HOWEVER WHITES OCCUPY WAY MORE MANAGERIAL POSITIONS THAN BLACKS"
dubois::db_area(
data = data, order = "year", cat1 = "black", cat2 = "white",
limits = c(-3, 4), filename = "managers.png",
title = title,
subtitle = subtitle,
message = message
)