From c5ad0b7fe8fa5f849a5ef0f04b2046ae224480ea Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 22 Dec 2016 11:34:14 -0500 Subject: [PATCH] added plot example readme --- DESCRIPTION | 2 +- README.Rmd | 33 +++++++++++++++++++++++++++++++-- README.md | 2 +- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5c7149d..cdd43af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Format numbers for publication; includes the removal of p-value formatter. Depends: R (>= 3.2.0) Suggests: testthat -Date: 2016-12-20 +Date: 2016-12-22 License: GPL-2 LazyData: TRUE Roxygen: list(wrap = FALSE) diff --git a/README.Rmd b/README.Rmd index 67cf8c0..eb7a596 100644 --- a/README.Rmd +++ b/README.Rmd @@ -7,7 +7,7 @@ output: --- ```{r, echo=FALSE} -pacman::p_load(numform, xtable, wakefield) +pacman::p_load(numform, xtable, wakefield, ggplot2) rinline <- function(code) { sprintf('``` `r %s` ```', code) } @@ -32,7 +32,8 @@ Download the [zip ball](https://github.com/trinker/numform/zipball/master) or [t ```r if (!require("pacman")) install.packages("pacman") -pacman::p_load_gh("trinker/numform") +pacman::p_load_current_gh("trinker/numform") +pacman::p_load(tidyverse) ``` # Contact @@ -107,6 +108,34 @@ f_dollar(c(0.0, 0, .2, -00.02, 1122222, pi)) %>% f_comma() ``` +## Plotting + +```r +library(tidyverse) +``` + +```{r} +data_frame( + revenue = rnorm(10000, 500000, 50000), + date = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 10000, TRUE), + site = sample(paste("Site", 1:5), 10000, TRUE) +) %>% + mutate( + dollar = f_dollar(revenue, digits = -3), + thous = f_thous(revenue), + thous_dollars = f_thous(revenue, prefix = '$'), + abb_month = f_month(date), + abb_week = f_weekday(date, distinct = TRUE) + ) %T>% + print() %>% + ggplot(aes(abb_week, revenue)) + + geom_jitter(width = .2, height = 0, alpha = .2) + + scale_y_continuous(label = function(x) x %>% f_thous(x, prefix = '$'))+ + facet_wrap(~site) + + theme_bw() +``` + + ## Modeling We can see its use in actual model reporting as well: diff --git a/README.md b/README.md index 79df3c7..b5f7eee 100644 --- a/README.md +++ b/README.md @@ -302,4 +302,4 @@ chunk: And then use `` `r report(mymod)` `` resulting in a report that looks like this: F(5, 30) = 36.07, p < .05. For Χ2 using proper HTML leads to Χ2(1) = .64, -p = .42. \ No newline at end of file +p = .42.