f_text_bar: Format Text Based Bar Plots

Description Usage Arguments Value Examples

View source: R/f_text_bar.R

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

1
2
3

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## 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()

## End(Not run)

numform documentation built on Oct. 10, 2021, 1:10 a.m.