Learn R Programming

numform (version 0.6.4)

f_text_bar: Format Text Based Bar Plots

Description

Use a text symbol to create scaled horizontal bar plots of numeric vectors. Note that you will have to coerce the table to a data.frame in order for the output to look pretty.

Usage

f_text_bar(x, symbol = "_", width = 9, ...)

ff_text_bar(...)

Arguments

x

A numeric vector.

symbol

A sumbol to use for the bars.

width

The max width of the bar.

ignored.

Value

Returns a vector of concatenated symbols as a string that represent x

Examples

Run this code
# NOT RUN {
library(dplyr)

mtcars %>%
    count(cyl, gear) %>%
    group_by(cyl) %>%
    mutate(
        p = numform::f_pp(n/sum(n))
    ) %>%
    ungroup() %>%
    mutate(
        cyl = numform::fv_runs(cyl),
        ` ` = f_text_bar(n)  ## Overall
    ) %>%
    as.data.frame()

mtcars %>%
    count(cyl, gear) %>%
    group_by(cyl) %>%
    mutate(
        p = numform::f_pp(n/sum(n)),
        ` ` = f_text_bar(n) ## within groups
    ) %>%
    ungroup() %>%
    mutate(
        cyl = numform::fv_runs(cyl),
        ` ` = f_text_bar(n)
    ) %>%
    as.data.frame()

mtcars %>%
    count(cyl, gear) %>%
    group_by(cyl) %>%
    mutate(
        p = numform::f_pp(n/sum(n)),
        `within` = f_text_bar(n, width = 3, symbol = '#')
    ) %>%
    ungroup() %>%
    mutate(
        cyl = numform::fv_runs(cyl),
        `overall` = f_text_bar(n, width = 30, symbol = '*')
    ) %>%
    as.data.frame() %>%
    pander::pander(split.tables = Inf, justify = alignment(.), style = 'simple')

## Drop the headers
mtcars %>%
    count(cyl, gear) %>%
    group_by(cyl) %>%
    mutate(
        p = numform::f_pp(n/sum(n)),
        `   ` = f_text_bar(n, symbol = '=')
    ) %>%
    ungroup() %>%
    mutate(
        cyl = numform::fv_runs(cyl),
        ` ` = f_text_bar(n, symbol = '#')
    ) %>%
    as.data.frame()
# }

Run the code above in your browser using DataLab