pre_plot: Put a tibble in form to plot

Description Usage Arguments Details Value Author(s) Examples

View source: R/pre_plot.R

Description

Convert a tibble built using freq_table or cont_table in a shape that makes it easy to plot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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 freq_table or the cont_table function, which should contain the center of the classes (x) and at least one measure of the frequencies or densities (one of f, n, p, d),

f

mandatory argument if the tibble contains more than one frequency or density,

plot

for object of class freq_table one of histogram, freqpoly, stacked, cumulative and lorenz (see the details section),

...

further arguments.

Details

The pre_plot function returns a tibble containing:

Value

a tibble

Author(s)

Yves Croissant

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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)

descstat documentation built on Feb. 17, 2021, 5:07 p.m.