{"id":13401448,"url":"https://github.com/trinker/numform","last_synced_at":"2025-03-16T13:31:17.459Z","repository":{"id":56934532,"uuid":"68654221","full_name":"trinker/numform","owner":"trinker","description":"tools to assist in the formatting of numbers and plots for publication","archived":false,"fork":false,"pushed_at":"2021-10-08T20:18:04.000Z","size":1643,"stargazers_count":52,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-16T02:47:09.164Z","etag":null,"topics":["number-formating","r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trinker.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-19T23:09:45.000Z","updated_at":"2025-03-09T10:12:26.000Z","dependencies_parsed_at":"2022-08-21T00:40:22.358Z","dependency_job_id":null,"html_url":"https://github.com/trinker/numform","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fnumform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fnumform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fnumform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fnumform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trinker","download_url":"https://codeload.github.com/trinker/numform/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243875122,"owners_count":20361951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["number-formating","r"],"created_at":"2024-07-30T19:01:02.746Z","updated_at":"2025-03-16T13:31:17.102Z","avatar_url":"https://github.com/trinker.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\ntitle: \"numform\"\ndate: \"`r format(Sys.time(), '%d %B, %Y')`\"\noutput:\n  md_document:\n    toc: true      \n---\n\n```{r, echo=FALSE, message=FALSE, warning=FALSE}\npacman::p_load(numform, xtable, wakefield, ggplot2, knitr, gridExtra, viridis, maps)\nrinline \u003c- function(code) { \n    sprintf('\u003ccode class=\"r\"\u003e``` `r %s` ```\u003c/code\u003e', code) \n} \ndesc \u003c- suppressWarnings(readLines(\"DESCRIPTION\"))\nregex \u003c- \"(^Version:\\\\s+)(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\"\nloc \u003c- grep(regex, desc)\nver \u003c- gsub(regex, \"\\\\2\", desc[loc])\n# verbadge \u003c- sprintf('\u003ca href=\"https://img.shields.io/badge/Version-%s-orange.svg\"\u003e\u003cimg src=\"https://img.shields.io/badge/Version-%s-orange.svg\" alt=\"Version\"/\u003e\u003c/a\u003e\u003c/p\u003e', ver, ver)\nverbadge \u003c- ''\n````\n\n```{r, echo=FALSE, message=FALSE, warning=FALSE}\nlibrary(dplyr)\nlibrary(pacman)\noptions(scipen=999)\nknit_hooks$set(htmlcap = function(before, options, envir) {\n  if(!before) {\n    paste('\u003cp class=\"caption\"\u003e\u003cb\u003e\u003cem\u003e',options$htmlcap,\"\u003c/em\u003e\u003c/b\u003e\u003c/p\u003e\",sep=\"\")\n    }\n    })\nknitr::opts_knit$set(self.contained = TRUE, cache = FALSE)\nknitr::opts_chunk$set(fig.path = \"tools/figure/\", warning = FALSE)\n```\n\n[![Build Status](https://travis-ci.org/trinker/numform.svg?branch=master)](https://travis-ci.org/trinker/numform)\n[![Coverage Status](https://coveralls.io/repos/trinker/numform/badge.svg?branch=master)](https://coveralls.io/github/trinker/numform) \n[![](https://cranlogs.r-pkg.org/badges/numform)](https://cran.r-project.org/package=numform)  \n`r verbadge`\n\n**numform** contains tools to assist in the formatting of numbers and plots for publication.  Tools include the removal of leading zeros, standardization of number of digits, addition of affixes, and a p-value formatter.  These tools combine the functionality of several 'base' functions such as `paste()`, `format()`, and `sprintf()` into specific use case functions that are named in a way that is consistent with usage, making their names easy to remember and easy to deploy.\n\n# Installation\n\nTo download the development version of **numform**:\n\nDownload the [zip ball](https://github.com/trinker/numform/zipball/master) or [tar ball](https://github.com/trinker/numform/tarball/master), decompress and run `R CMD INSTALL` on it, or use the **pacman** package to install the development version:\n\n```r\nif (!require(\"pacman\")) install.packages(\"pacman\")\npacman::p_load_current_gh(\"trinker/numform\")\npacman::p_load(tidyverse, gridExtra)\n```\n\n# Contact\n\nYou are welcome to:\n* submit suggestions and bug-reports at: \u003chttps://github.com/trinker/numform/issues\u003e\n* send a pull request on: \u003chttps://github.com/trinker/numform\u003e\n* compose a friendly e-mail to: \u003ctyler.rinker@gmail.com\u003e\n\n# Available Functions\n\nBelow is a table of available **numform** functions.  Note that `f_` is read as \"format\" whereas `fv_` is read as \"format vector\".  The former formats individual values in the vector while the latter uses the vector to compute a calculation on each of the values and then formats them.  Additionally, all **numform** `f_` functions have a closure, function retuning, version that is prefixed with an additional `f` (read \"format function\").  For example, `f_num` has `ff_num` which has the same arguments but returns a function instead.  This is useful for passing in to **ggplot2** `scale_x/y_type` functions (see [Plotting](#plotting) for usage).\n\n\n```{r, results='asis', echo=FALSE, comment=NA, warning=FALSE, htmlcap=\"Available Formatting Functions\"}\np_funs(numform) %\u003e%\n    {grep(\"^ff\", ., invert = TRUE, value = TRUE)} %\u003e%\n    wakefield:::variables_as_matrix() %\u003e%\n    xtable::xtable() %\u003e%\n    print(type = 'html', include.colnames = FALSE, include.rownames = FALSE,\n        html.table.attributes = '')\n```\n\n\n# Demonstration\n\n## Load Packages\n\n```{r}\nif (!require(\"pacman\")) install.packages(\"pacman\")\npacman::p_load_gh(\"trinker/numform\")\npacman::p_load(dplyr)\n```\n\n## Numbers\n\n```{r, warn=FALSE}\nf_num(c(0.0, 0, .2, -00.02, 1.122222, pi, \"A\"))\n```\n\n## Abbreviated Numbers\n\n```{r, warn=FALSE}\nf_thous(1234)\nf_thous(12345)\nf_thous(123456)\nf_mills(1234567)\nf_mills(12345678)\nf_mills(123456789)\nf_bills(1234567891)\nf_bills(12345678912)\nf_bills(123456789123)\n```\n\n...or auto-detect:\n\n```{r}\nf_denom(1234)\nf_denom(12345)\nf_denom(123456)\nf_denom(1234567)\nf_denom(12345678)\nf_denom(123456789)\nf_denom(1234567891)\nf_denom(12345678912)\nf_denom(123456789123)\n```\n\n## Commas\n\n```{r, warn=FALSE}\nf_comma(c(1234.12345, 1234567890, .000034034, 123000000000, -1234567))\n```\n\n## Percents\n\n```{r, warn=FALSE}\nf_percent(c(30, 33.45, .1), digits = 1)\nf_percent(c(0.0, 0, .2, -00.02, 1.122222, pi))\nf_prop2percent(c(.30, 1, 1.01, .33, .222, .01))\nf_prop2percent(c(.30, 1, 1.01, .33, .222, .01), digits = 0)\nf_pp(c(.30, 1, 1.01, .33, .222, .01)) # same as f_prop2percent(digits = 0)\n```\n\n## Dollars\n\n```{r, warn=FALSE}\nf_dollar(c(0, 30, 33.45, .1))\nf_dollar(c(0.0, 0, .2, -00.02, 1122222, pi)) %\u003e% \n    f_comma()\n```\n\nSometimes one wants to lop off digits of money in order to see the important digits, the real story.  The `f_denom` family of functions can do job.\n\n```{r, warn=FALSE}\nf_denom(c(12345267, 98765433, 658493021), prefix = '$')\nf_denom(c(12345267, 98765433, 658493021), relative = 1, prefix = '$')\n```\n\n## Tables\n\nNotice the use of the `alignment` function to detect the column alignment.\n\n```{r}\npacman::p_load(dplyr, pander)\n\nset.seed(10)\ndat \u003c- data_frame(\n    Team = rep(c(\"West Coast\", \"East Coast\"), each = 4),\n    Year = rep(2012:2015, 2),\n    YearStart = round(rnorm(8, 2e6, 1e6) + sample(1:10/100, 8, TRUE), 2),\n    Won = round(rnorm(8, 4e5, 2e5) + sample(1:10/100, 8, TRUE), 2),\n    Lost = round(rnorm(8, 4.4e5, 2e5) + sample(1:10/100, 8, TRUE), 2),\n    WinLossRate = Won/Lost,\n    PropWon = Won/YearStart,\n    PropLost = Lost/YearStart\n)\n\n\ndat %\u003e%\n    group_by(Team) %\u003e%\n    mutate(\n        `%\u0026Delta;WinLoss` = fv_percent_diff(WinLossRate, 0),\n        `\u0026Delta;WinLoss` = f_sign(Won - Lost, '\u003cb\u003e+\u003c/b\u003e', '\u003cb\u003e\u0026ndash;\u003c/b\u003e')\n        \n    ) %\u003e%\n    ungroup() %\u003e%\n    mutate_at(vars(Won:Lost), .funs = ff_denom(relative = -1, prefix = '$')) %\u003e%\n    mutate_at(vars(PropWon, PropLost), .funs = ff_prop2percent(digits = 0)) %\u003e%\n    mutate(\n        YearStart = f_denom(YearStart, 1, prefix = '$'),\n        Team = fv_runs(Team),\n        WinLossRate = f_num(WinLossRate, 1)\n    ) %\u003e%\n    data.frame(stringsAsFactors = FALSE, check.names = FALSE) %\u003e%\n    pander::pander(split.tables = Inf, justify = alignment(.), style = 'simple')\n```\n\n```{r}\npacman::p_load(dplyr, pander)\n\ndata_frame(\n    Event = c('freezing water', 'room temp', 'body temp', 'steak\\'s done', 'hamburger\\'s done', 'boiling water', 'sun surface', 'lighting'),\n    F = c(32, 70, 98.6, 145, 160, 212, 9941, 50000)\n) %\u003e%\n    mutate(\n        Event = f_title(Event),\n        C = (F - 32) * (5/9)\n    ) %\u003e%\n    mutate(\n        F = f_degree(F, measure = 'F', type = 'string'),\n        C = f_degree(C, measure = 'C', type = 'string', zero = '0.0')\n    )  %\u003e%\n    data.frame(stringsAsFactors = FALSE, check.names = FALSE) %\u003e%\n    pander::pander(split.tables = Inf, justify = alignment(.), style = 'simple')\n```\n\n\n```{r, comment = NA}\nif (!require(\"pacman\")) install.packages(\"pacman\")\npacman::p_load(tidyverse)\n\nset.seed(11)\ndata_frame(\n    date = sample(seq(as.Date(\"1990/1/1\"), by = \"day\", length.out = 2e4), 12)\n) %\u003e%\n    mutate(\n        year_4 = f_year(date, 4),\n        year_2 = f_year(date, 2),\n        quarter = f_quarter(date),\n        month_name = f_month_name(date) %\u003e%\n            numform::as_factor(),\n        month_abbreviation = f_month_abbreviation(date) %\u003e%\n            numform::as_factor(),\n        month_short = f_month(date),\n        weekday_name = f_weekday_name(date),\n        weekday_abbreviation = f_weekday_abbreviation(date),\n       weekday_short = f_weekday(date),\n        weekday_short_distinct = f_weekday(date, distinct = TRUE)\n    ) %\u003e%\n    data.frame(stringsAsFactors = FALSE, check.names = FALSE) %\u003e%\n    pander::pander(split.tables = Inf, justify = alignment(.), style = 'simple')\n```\n\n```{r, comment=NA}\nmtcars %\u003e%\n    count(cyl, gear) %\u003e%\n    group_by(cyl) %\u003e%\n    mutate(\n        p = numform::f_pp(n/sum(n))\n    ) %\u003e%\n    ungroup() %\u003e%\n    mutate(\n        cyl = numform::fv_runs(cyl),\n        ` ` = f_text_bar(n)  ## Overall\n    ) %\u003e%\n    as.data.frame()\n```\n\n## Plotting\n\n```r\nlibrary(tidyverse); library(viridis)\n```\n\n```{r}\nset.seed(10)\ndata_frame(\n    revenue = rnorm(10000, 500000, 50000),\n    date = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by=\"day\"), 10000, TRUE),\n    site = sample(paste(\"Site\", 1:5), 10000, TRUE)\n) %\u003e%\n    mutate(\n        dollar = f_comma(f_dollar(revenue, digits = -3)),\n        thous = f_denom(revenue),\n        thous_dollars = f_denom(revenue, prefix = '$'),\n        abb_month = f_month(date),\n        abb_week = numform::as_factor(f_weekday(date, distinct = TRUE))\n    ) %\u003e%\n    group_by(site, abb_week) %\u003e%\n    mutate(revenue = {if(sample(0:1, 1) == 0) `-` else `+`}(revenue, sample(1e2:1e5, 1))) %\u003e%\n    ungroup() %T\u003e%\n    print() %\u003e%\n    ggplot(aes(abb_week, revenue)) +\n        geom_jitter(width = .2, height = 0, alpha = .2, aes(color = revenue)) +\n        scale_y_continuous(label = ff_denom(prefix = '$'))+\n        facet_wrap(~site) +\n        theme_bw() +\n        scale_color_viridis() +\n        theme(\n            strip.text.x = element_text(hjust = 0, color = 'grey45'),\n            strip.background = element_rect(fill = NA, color = NA),\n            panel.border = element_rect(fill = NA, color = 'grey75'),\n            panel.grid = element_line(linetype = 'dotted'),\n            axis.ticks = element_line(color = 'grey55'),\n            axis.text = element_text(color = 'grey55'),\n            axis.title.x = element_text(color = 'grey55', margin = margin(t = 10)),            \n            axis.title.y = element_text(color = 'grey55', angle = 0, margin = margin(r = 10)),\n            legend.position = 'none'\n        ) +\n        labs(\n            x = 'Day of Week',\n            y = 'Revenue',\n            title = 'Site Revenue by Day of Week',\n            subtitle = f_wrap(c(\n                'This faceted dot plot shows the distribution of revenues within sites',\n                'across days of the week.  Notice the consistently increasing revenues for',\n                'Site 2 across the week.'\n            ), width = 85, collapse = TRUE)\n        )\n```\n\n\n\n```r\nlibrary(tidyverse); library(viridis)\n```\n\n```{r}\nset.seed(10)\ndat \u003c- data_frame(\n    revenue = rnorm(144, 500000, 10000),\n    date = seq(as.Date('2005/01/01'), as.Date('2016/12/01'), by=\"month\")\n) %\u003e%\n    mutate(\n        quarter = f_quarter(date),\n        year = f_year(date, 4)\n    ) %\u003e%\n    group_by(year, quarter) %\u003e%\n    summarize(revenue = sum(revenue)) %\u003e%\n    ungroup() %\u003e%\n    mutate(quarter = as.integer(gsub('Q', '', quarter)))\n\nyear_average \u003c- dat %\u003e%\n    group_by(year) %\u003e%\n    summarize(revenue = mean(revenue)) %\u003e%\n    mutate(x1 = .8, x2 = 4.2)\n\ndat %\u003e%\n    ggplot(aes(quarter, revenue, group = year)) +\n        geom_segment(\n            linetype = 'dashed', \n            data = year_average, color = 'grey70', size = 1,\n            aes(x = x1, y = revenue, xend = x2, yend = revenue)\n        ) +\n        geom_line(size = .85, color = '#009ACD') +\n        geom_point(size = 1.5, color = '#009ACD') +\n        facet_wrap(~year, nrow = 2)  +\n        scale_y_continuous(label = ff_denom(relative = 2)) +\n        scale_x_continuous(breaks = 1:4, label = f_quarter) +\n        theme_bw() +\n        theme(\n            strip.text.x = element_text(hjust = 0, color = 'grey45'),\n            strip.background = element_rect(fill = NA, color = NA),\n            panel.border = element_rect(fill = NA, color = 'grey75'),\n            panel.grid.minor = element_blank(),\n            panel.grid.major = element_line(linetype = 'dotted'),\n            axis.ticks = element_line(color = 'grey55'),\n            axis.text = element_text(color = 'grey55'),\n            axis.title.x = element_text(color = 'grey55', margin = margin(t = 10)),            \n            axis.title.y = element_text(color = 'grey55', angle = 0, margin = margin(r = 10)),\n            legend.position = 'none'\n        ) +\n        labs(\n            x = 'Quarter',\n            y = 'Revenue ($)',\n            title = 'Quarterly Revenue Across Years',\n            subtitle = f_wrap(c(\n                'This faceted line plot shows the change in quarterly revenue across', \n                'years.'\n            ), width = 85, collapse = TRUE)\n        )\n        \n```\n\n\n```r\nlibrary(tidyverse); library(gridExtra)\n```\n\n\n```{r, fig.width = 9}\nset.seed(10)\ndat \u003c- data_frame(\n    level = c(\"not_involved\", \"somewhat_involved_single_group\",\n        \"somewhat_involved_multiple_groups\", \"very_involved_one_group\",\n        \"very_involved_multiple_groups\"\n    ),\n    n = sample(1:10, length(level))\n) %\u003e%\n    mutate(\n        level = factor(level, levels = unique(level)),\n        `%` = n/sum(n)\n    )\n\ngridExtra::grid.arrange(\n\n    gridExtra::arrangeGrob(\n\n        dat %\u003e%\n            ggplot(aes(level, `%`)) +\n                geom_col() +\n                labs(title = 'Very Sad', y = NULL) +\n                theme(\n                    axis.text = element_text(size = 7),\n                    title = element_text(size = 9)\n                ),\n\n       dat %\u003e%\n            ggplot(aes(level, `%`)) +\n                geom_col() +\n                scale_x_discrete(labels = function(x) f_replace(x, '_', '\\n')) +\n                scale_y_continuous(labels = ff_prop2percent(digits = 0))  +\n                labs(title = 'Underscore Split (Readable)', y = NULL) +\n                theme(\n                    axis.text = element_text(size = 7),\n                    title = element_text(size = 9)\n                ),\n\n\n        ncol = 2\n\n    ),\n    gridExtra::arrangeGrob(\n\n       dat %\u003e%\n            ggplot(aes(level, `%`)) +\n                geom_col() +\n                scale_x_discrete(labels = function(x) f_title(f_replace(x))) +\n                scale_y_continuous(labels = ff_prop2percent(digits = 0))  +\n                labs(title = 'Underscore Replaced \u0026 Title (Capitalized Sadness)', y = NULL) +\n                theme(\n                    axis.text = element_text(size = 7),\n                    title = element_text(size = 9)\n                ),\n\n        dat %\u003e%\n            ggplot(aes(level, `%`)) +\n                geom_col() +\n                scale_x_discrete(labels = function(x) f_wrap(f_title(f_replace(x)))) +\n                scale_y_continuous(labels = ff_prop2percent(digits = 0))  +\n                labs(title = 'Underscore Replaced, Title, \u0026 Wrapped (Happy)', y = NULL) +\n                theme(\n                    axis.text = element_text(size = 7),\n                    title = element_text(size = 9)\n                ),\n\n        ncol = 2\n\n    ), ncol = 1\n\n)\n```\n\n\n\n```{r, fig.width = 6}\nset.seed(10)\ndat \u003c- data_frame(\n    state = sample(state.name, 10),\n    value = sample(10:20, 10) ^ (7),\n    cols = sample(colors()[1:150], 10)\n) %\u003e%\n    arrange(desc(value)) %\u003e%\n    mutate(state = factor(state, levels = unique(state)))\n\ndat %\u003e%\n    ggplot(aes(state, value, fill = cols)) +\n        geom_col() +\n        scale_x_discrete(labels = f_state) +\n        scale_fill_identity() +\n        scale_y_continuous(labels = ff_denom(prefix = '$'), expand = c(0, 0), \n            limits = c(0, max(dat$value) * 1.05)\n        ) +\n        theme_minimal() +\n        theme(\n            panel.grid.major.x = element_blank(),\n            axis.title.y = element_text(angle = 0)\n        ) +\n        labs(x = 'State', y = 'Cash\\nFlow', \n            title = f_title(\"look at how professional i look\"),\n            subtitle = 'Subtitles: For that extra professional look.'\n        )\n```\n\n\n```r\nlibrary(tidyverse); library(viridis)\n```\n\n```{r, fig.width = 7, fig.height = 6}\ndata_frame(\n    Event = c('freezing water', 'room temp', 'body temp', 'steak\\'s done', 'hamburger\\'s done', 'boiling water'),\n    F = c(32, 70, 98.6, 145, 160, 212)\n) %\u003e%\n    mutate(\n        C = (F - 32) * (5/9),\n        Event = f_title(Event),\n        Event = factor(Event, levels = unique(Event))\n    ) %\u003e%\n    ggplot(aes(Event, F, fill = F)) +\n        geom_col() +\n        geom_text(aes(y = F + 4, label = f_fahrenheit(F, digits = 1, type = 'text')), parse = TRUE, color = 'grey60') +\n        scale_y_continuous(\n            labels = f_fahrenheit, limits = c(0, 220), expand = c(0, 0),\n            sec.axis = sec_axis(trans = ~(. - 32) * (5/9), labels = f_celcius, name = f_celcius(prefix = 'Temperature ', type = 'title'))\n        ) +\n        scale_x_discrete(labels = ff_replace(pattern = ' ', replacement = '\\n')) +\n        scale_fill_viridis(option =  \"magma\", labels = f_fahrenheit, name = NULL) +\n        theme_bw() +\n        labs(\n            y = f_fahrenheit(prefix = 'Temperature ', type = 'title'),\n            title = f_fahrenheit(prefix = 'Temperature of Common Events ', type = 'title')\n        ) +\n        theme(\n            axis.ticks.x = element_blank(),\n            panel.border = element_rect(fill = NA, color = 'grey80'),\n            panel.grid.minor.x = element_blank(),\n            panel.grid.major.x = element_blank()\n        )\n```\n\n\n```r\nlibrary(tidyverse); library(maps)\n```\n\n```{r, fig.width = 7, fig.height = 5}\nworld \u003c- map_data(map=\"world\")\n\nggplot(world, aes(map_id = region, x = long, y = lat)) +\n    geom_map(map = world, aes(map_id = region), fill = \"grey40\", colour = \"grey70\", size = 0.25) +\n    scale_y_continuous(labels = f_latitude) +\n    scale_x_continuous(labels = f_longitude)\n```\n\n\n```{r, fig.width = 7, fig.height = 5}\nmtcars %\u003e%\n    mutate(mpg2 = cut(mpg, 10, right = FALSE)) %\u003e%\n    ggplot(aes(mpg2)) +\n        geom_bar(fill = '#33A1DE') +\n        scale_x_discrete(labels = function(x) f_wrap(f_bin_text_right(x, l = 'up to'), width = 8)) +\n        scale_y_continuous(breaks = seq(0, 14, by = 2), limits = c(0, 7)) +\n        theme_minimal() +\n        theme(\n            panel.grid.major.x = element_blank(),\n            axis.text.x = element_text(size = 14, margin = margin(t = -12)),\n            axis.text.y = element_text(size = 14),\n            plot.title = element_text(hjust = .5)\n        ) +\n        labs(title = 'Histogram', x = NULL, y = NULL)\n```\n\n\n```{r}\ndat \u003c- data_frame(\n    Value = c(111, 2345, 34567, 456789, 1000001, 1000000001),\n    Time = 1:6\n)\n\ngridExtra::grid.arrange(\n    \n    ggplot(dat, aes(Time, Value)) +\n        geom_line() +\n        scale_y_continuous(labels = ff_denom( prefix = '$')) +\n        labs(title = \"Single Denominational Unit\"),\n    \n    ggplot(dat, aes(Time, Value)) +\n        geom_line() +\n        scale_y_continuous(\n            labels = ff_denom(mix.denom = TRUE, prefix = '$', pad.char = '')\n        ) +\n        labs(title = \"Mixed Denominational Unit\"),\n    \n    ncol = 2\n)\n```\n    \n## Modeling\n\nWe can see its use in actual model reporting as well:\n\n\n```{r}\nmod1 \u003c- t.test(1:10, y = c(7:20))\n\nsprintf(\n    \"t = %s (%s)\",\n    f_num(mod1$statistic),\n    f_pval(mod1$p.value)\n)\n```\n\n```{r}\nmod2 \u003c- t.test(1:10, y = c(7:20, 200))\n\nsprintf(\n    \"t = %s (%s)\",\n    f_num(mod2$statistic, 2),\n    f_pval(mod2$p.value, digits = 2)\n)\n```\n\nWe can build a function to report model statistics:\n\n```{r}\nreport \u003c- function(mod, stat = NULL, digits = c(0, 2, 2)) {\n    \n    stat \u003c- if (is.null(stat)) stat \u003c- names(mod[[\"statistic\"]])\n    sprintf(\n        \"%s(%s) = %s, %s\", \n        gsub('X-squared', '\u0026Chi;\u003csup\u003e2\u003c/sup\u003e', stat),\n        paste(f_num(mod[[\"parameter\"]], digits[1]), collapse = \", \"),\n        f_num(mod[[\"statistic\"]], digits[2]),\n        f_pval(mod[[\"p.value\"]], digits = digits[3])\n    )\n\n}\n\nreport(mod1)\nreport(oneway.test(count ~ spray, InsectSprays))\nreport(chisq.test(matrix(c(12, 5, 7, 7), ncol = 2)))\n```\n\nThis enables in-text usage as well.  First set up the models in a code chunk:\n\n```{r}\nmymod \u003c- oneway.test(count ~ spray, InsectSprays)\nmymod2 \u003c- chisq.test(matrix(c(12, 5, 7, 7), ncol = 2))\n```\n\nAnd then use `r rinline(\"report(mymod)\")` resulting in a report that looks like this: `r report(mymod)`.  For \u0026Chi;\u003csup\u003e2\u003c/sup\u003e using proper HTML leads to `r report(mymod2)`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Fnumform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrinker%2Fnumform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Fnumform/lists"}