| pre_plot {descstat} | R Documentation |
Put a tibble in form to plot
Description
Convert a tibble built using freq_table or cont_table in a
shape that makes it easy to plot.
Usage
pre_plot(data, f = NULL, plot = NULL, ...)
## S3 method for class 'freq_table'
pre_plot(
data,
f = NULL,
plot = c("histogram", "freqpoly", "lorenz", "stacked", "cumulative"),
...
)
## S3 method for class 'cont_table'
pre_plot(data, ...)
Arguments
data |
a tibble returned by the |
f |
mandatory argument if the tibble contains more than one frequency or density, |
plot |
for object of class |
... |
further arguments. |
Details
The pre_plot function returns a tibble containing:
if
plot = histogram,x,ythat should be passed togeom_polygon,if
plot = freqpolyxandythat should be passed togeom_line,if
plot = stackedxandyposthat should be passed respectively togeom_coland togeom_textto draw labels on the right position,if
plot = cumulativex,y,xendandyendthat should be passed togeom_segment,if
plot = lorenzfor the Lorenz curve,FandMfor the coordinates of the polygons under the Lorenz curve,ptsis logical which the defines the subset of points that belongs to the Lorenz curve.
Value
a tibble
Author(s)
Yves Croissant
Examples
library("dplyr")
library("ggplot2")
pad <- padova %>%
freq_table(price, breaks = c(100, 200, 300, 400, 500, 1000),
right = TRUE, f = "Npd")
pad %>% pre_plot(f = "d") %>% ggplot() + geom_polygon(aes(x, y))
pad %>% pre_plot(f = "d", plot = "freqpoly") %>%
ggplot() + geom_line(aes(x, y))
## A pie chart
wages %>% freq_table(sector, "p", total = FALSE) %>%
pre_plot("p", plot = "stacked") %>% ggplot(aes(x = 2, y = p, fill = sector)) +
geom_col() + geom_text(aes(y = ypos, label = sector)) +
coord_polar(theta = "y") + theme_void() + guides(fill = FALSE)