numform (version 0.5.0)

fv_percent: Convert a Numeric Vector to Percentages

Description

Converts a numeric vector into a vector of relative percentages.

Usage

fv_percent(x, digits = getOption("numformdigits"), ...)

ffv_percent(...)

ffv_percent(...)

Arguments

x

A numeric vector.

digits

The number of digits to use. Defaults to 1. Can be set globally via: options(numformdigits = n) where n is the number of digits beyond the decimal point to include.

Other arguments passed to f_prop2percent.

Value

Returns a string of publication ready relative percentages.

Examples

Run this code
# NOT RUN {
fv_percent(1:4)
fv_percent(sample(1:100, 20))
# }
# NOT RUN {
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse)

mtcars %>%
    count(cyl, gear) %>%
    group_by(cyl) %>%
    mutate(perc = fv_percent(n, digits = 0))

mtcars %>%
    count(cyl, gear) %>%
    group_by(cyl) %>%
    mutate(perc = fv_percent(n, digits = 0)) %>%
    ggplot(aes(gear, n)) +
        geom_bar(stat = 'identity') +
        facet_wrap(~cyl, ncol = 1) +
        geom_text(aes(y = n + 1, label = perc))
# }

Run the code above in your browser using DataCamp Workspace