diff --git a/.Rbuildignore b/.Rbuildignore index 319caf0..0df24b8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -11,3 +11,4 @@ ^notes$ ^cran-comments\.md$ ^README_figs$ +^docs$ diff --git a/DESCRIPTION b/DESCRIPTION index bb6d3c5..4ad4e2f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: hrbrthemes Type: Package Title: Additional Themes, Theme Components and Utilities for 'ggplot2' -Version: 0.1.0 -Date: 2017-02-25 +Version: 0.2.0 +Date: 2017-03-01 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre")), person("Google", comment = "Roboto Condensed Font", role = c("cph")) @@ -22,7 +22,11 @@ Suggests: knitr, rmarkdown, gridExtra, - gcookbook + hunspell, + stringi, + gcookbook, + vdiffr, + svglite Depends: R (>= 3.2.0) Imports: @@ -30,8 +34,6 @@ Imports: grid, scales, extrafont, - hunspell, - stringi, purrr -RoxygenNote: 6.0.0 +RoxygenNote: 6.0.1 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 03829a6..6957e4f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,9 +20,7 @@ export(update_geom_font_defaults) import(extrafont) import(ggplot2) import(grid) -import(hunspell) import(scales) -import(stringi) importFrom(purrr,"%>%") importFrom(purrr,map) importFrom(purrr,walk) diff --git a/NEWS.md b/NEWS.md index e50bfef..cb66363 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# hrbrthemes 0.2.0 + +## Changed Stuff + +* Added `vdiffr` tests for the two core themes. +* Moved `hunspell` and `stringi` to `Suggests` and added namespace tests to `gg_check()`. +* Added `dict` and `ignore` parameters (with defaults) to `gg_check()` (@karldw) [PR #3]. +* Fixed typos (@benmarwick) [PR #1]. +* Spelling in vignette fixed (@zx8754) [Issue #6]. +* New lighter grid color default (`#cccccc`) [Issue #7]. + + # hrbrthemes 0.1.0 ## New Stuff diff --git a/R/aaa.r b/R/aaa.r index e69de29..ede51bc 100644 --- a/R/aaa.r +++ b/R/aaa.r @@ -0,0 +1,9 @@ +try_require <- function(package, fun) { + if (requireNamespace(package, quietly = TRUE)) { + library(package, character.only = TRUE) + return(invisible()) + } + + stop("Package `", package, "` required for `", fun , "`.\n", # nocov start + "Please install and try again.", call. = FALSE) # nocov end +} \ No newline at end of file diff --git a/R/check.r b/R/check.r index d914a52..baaba96 100644 --- a/R/check.r +++ b/R/check.r @@ -10,8 +10,10 @@ #' #' @md #' @param gg ggplot2 object -#' @param dict a dictionary object or string which can be passed to [hunspell::dictionary] -#' @param ignore character vector with additional approved words added to the dictionary +#' @param dict a dictionary object or string which can be passed to [hunspell::dictionary]. +#' Defaults to `hunspell::dictionary("en_US")` +#' @param ignore character vector with additional approved words added to the dictionary. +#' Defaults to `hunspell::en_stats` #' @return the object that was passed in #' @export #' @examples @@ -28,7 +30,13 @@ #' caption="This is a captien") -> gg #' #' gg_check(gg) -gg_check <- function(gg, dict = hunspell::dictionary("en_US"), ignore = hunspell::en_stats) { +gg_check <- function(gg, dict, ignore) { + + try_require("hunspell", "hunspell") + try_require("stringi", "stri_extract_all_words") + + if (missing(dict)) dict <- hunspell::dictionary("en_US") + if (missing(ignore)) ignore <- hunspell::en_stats if (inherits(gg, "labels")) { lbl <- gg @@ -42,9 +50,9 @@ gg_check <- function(gg, dict = hunspell::dictionary("en_US"), ignore = hunspell purrr::walk(names(lbl), function(lab) { - words <- stri_extract_all_words(lbl[[lab]]) + words <- stringi::stri_extract_all_words(lbl[[lab]]) words <- unlist(words) - words <- purrr::discard(hunspell(words, "text", dict = dict, ignore = ignore), + words <- purrr::discard(hunspell::hunspell(words, "text", dict = dict, ignore = ignore), ~length(.)==0) if (length(words) > 0) { diff --git a/R/hrbrthemes-package.R b/R/hrbrthemes-package.R index 8f22ca3..9ff918c 100644 --- a/R/hrbrthemes-package.R +++ b/R/hrbrthemes-package.R @@ -15,7 +15,7 @@ #' @name hrbrthemes #' @docType package #' @author Bob Rudis (bob@@rud.is) -#' @import ggplot2 grid scales extrafont hunspell stringi +#' @import ggplot2 grid scales extrafont #' @importFrom purrr %>% map walk NULL diff --git a/R/roboto-condensed.r b/R/roboto-condensed.r index 3834c3b..4ff5e39 100644 --- a/R/roboto-condensed.r +++ b/R/roboto-condensed.r @@ -18,7 +18,9 @@ #' @param axis_title_family,axis_title_face,axis_title_size axis title font family, face and size #' @param axis_title_just axis title font justificationk one of `[blmcrt]` #' @param plot_margin plot margin (specify with [ggplot2::margin]) +#' @param grid_col grid color #' @param grid panel grid (`TRUE`, `FALSE`, or a combination of `X`, `x`, `Y`, `y`) +#' @param axis_col axis color #' @param axis add x or y axes? `TRUE`, `FALSE`, "`xy`" #' @param ticks ticks if `TRUE` add ticks #' @export @@ -62,7 +64,8 @@ theme_ipsum_rc <- function(base_family="Roboto Condensed", base_size = 11, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = margin(30, 30, 30, 30), - grid = TRUE, axis = FALSE, ticks = FALSE) { + grid_col = "#2b2b2b99", grid = TRUE, + axis_col = "#2b2b2b", axis = FALSE, ticks = FALSE) { ret <- ggplot2::theme_minimal(base_family=base_family, base_size=base_size) @@ -71,9 +74,9 @@ theme_ipsum_rc <- function(base_family="Roboto Condensed", base_size = 11, if (inherits(grid, "character") | grid == TRUE) { - ret <- ret + theme(panel.grid=element_line(color="#2b2b2bdd", size=0.10)) - ret <- ret + theme(panel.grid.major=element_line(color="#2b2b2b99", size=0.10)) - ret <- ret + theme(panel.grid.minor=element_line(color="#2b2b2b99", size=0.05)) + ret <- ret + theme(panel.grid=element_line(color=grid_col, size=0.10)) + ret <- ret + theme(panel.grid.major=element_line(color=grid_col, size=0.10)) + ret <- ret + theme(panel.grid.minor=element_line(color=grid_col, size=0.05)) if (inherits(grid, "character")) { if (regexpr("X", grid)[1] < 0) ret <- ret + theme(panel.grid.major.x=element_blank()) @@ -87,22 +90,22 @@ theme_ipsum_rc <- function(base_family="Roboto Condensed", base_size = 11, } if (inherits(axis, "character") | axis == TRUE) { - ret <- ret + theme(axis.line=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line=element_line(color=axis_col, size=0.15)) if (inherits(axis, "character")) { axis <- tolower(axis) if (regexpr("x", axis)[1] < 0) { ret <- ret + theme(axis.line.x=element_blank()) } else { - ret <- ret + theme(axis.line.x=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line.x=element_line(color=axis_col, size=0.15)) } if (regexpr("y", axis)[1] < 0) { ret <- ret + theme(axis.line.y=element_blank()) } else { - ret <- ret + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line.y=element_line(color=axis_col, size=0.15)) } } else { - ret <- ret + theme(axis.line.x=element_line(color="#2b2b2b", size=0.15)) - ret <- ret + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line.x=element_line(color=axis_col, size=0.15)) + ret <- ret + theme(axis.line.y=element_line(color=axis_col, size=0.15)) } } else { ret <- ret + theme(axis.line=element_blank()) diff --git a/R/theme-ipsum.r b/R/theme-ipsum.r index 7ba13bf..2f08fb5 100644 --- a/R/theme-ipsum.r +++ b/R/theme-ipsum.r @@ -28,6 +28,7 @@ #' @param axis_title_family,axis_title_face,axis_title_size axis title font family, face and size #' @param axis_title_just axis title font justification, one of `[blmcrt]` #' @param plot_margin plot margin (specify with [ggplot2::margin]) +#' @param grid_col,axis_col grid & axis colors; both default to `#cccccc` #' @param grid panel grid (`TRUE`, `FALSE`, or a combination of `X`, `x`, `Y`, `y`) #' @param axis add x or y axes? `TRUE`, `FALSE`, "`xy`" #' @param ticks ticks if `TRUE` add ticks @@ -72,7 +73,8 @@ theme_ipsum <- function(base_family="Arial Narrow", base_size = 11, axis_title_family = subtitle_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = margin(30, 30, 30, 30), - grid = TRUE, axis = FALSE, ticks = FALSE) { + grid_col = "#cccccc", grid = TRUE, + axis_col = "#cccccc", axis = FALSE, ticks = FALSE) { ret <- ggplot2::theme_minimal(base_family=base_family, base_size=base_size) @@ -81,9 +83,9 @@ theme_ipsum <- function(base_family="Arial Narrow", base_size = 11, if (inherits(grid, "character") | grid == TRUE) { - ret <- ret + theme(panel.grid=element_line(color="#2b2b2bdd", size=0.10)) - ret <- ret + theme(panel.grid.major=element_line(color="#2b2b2b99", size=0.10)) - ret <- ret + theme(panel.grid.minor=element_line(color="#2b2b2b99", size=0.05)) + ret <- ret + theme(panel.grid=element_line(color=grid_col, size=0.10)) + ret <- ret + theme(panel.grid.major=element_line(color=grid_col, size=0.10)) + ret <- ret + theme(panel.grid.minor=element_line(color=grid_col, size=0.05)) if (inherits(grid, "character")) { if (regexpr("X", grid)[1] < 0) ret <- ret + theme(panel.grid.major.x=element_blank()) @@ -103,16 +105,16 @@ theme_ipsum <- function(base_family="Arial Narrow", base_size = 11, if (regexpr("x", axis)[1] < 0) { ret <- ret + theme(axis.line.x=element_blank()) } else { - ret <- ret + theme(axis.line.x=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line.x=element_line(color=axis_col, size=0.15)) } if (regexpr("y", axis)[1] < 0) { ret <- ret + theme(axis.line.y=element_blank()) } else { - ret <- ret + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line.y=element_line(color=axis_col, size=0.15)) } } else { - ret <- ret + theme(axis.line.x=element_line(color="#2b2b2b", size=0.15)) - ret <- ret + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15)) + ret <- ret + theme(axis.line.x=element_line(color=axis_col, size=0.15)) + ret <- ret + theme(axis.line.y=element_line(color=axis_col, size=0.15)) } } else { ret <- ret + theme(axis.line=element_blank()) diff --git a/README.md b/README.md index eea5093..5bc3a99 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ library(tidyverse) # current verison packageVersion("hrbrthemes") -## [1] '0.1.0' +## [1] '0.2.0' ``` ### Base theme (Arial Narrow) @@ -166,11 +166,11 @@ library(hrbrthemes) library(testthat) date() -## [1] "Mon Feb 27 07:03:41 2017" +## [1] "Wed Mar 1 22:17:40 2017" test_dir("tests/") ## testthat results ======================================================================================================== -## OK: 10 SKIPPED: 0 FAILED: 0 +## OK: 12 SKIPPED: 0 FAILED: 0 ## ## DONE =================================================================================================================== ``` diff --git a/docs/articles/why_hrbrthemes.html b/docs/articles/why_hrbrthemes.html index d142f61..35d0758 100644 --- a/docs/articles/why_hrbrthemes.html +++ b/docs/articles/why_hrbrthemes.html @@ -45,7 +45,7 @@
  • - +
  • @@ -55,18 +55,18 @@ - +
    - - + +

    The hrbrthemes pacakge has two goals. First, it provides a base theme that focuses on typographic elements, including where various labels are placed as well as the fonts that are used. The second goal centers around productivity for a production workflow. In fact, this “production workflow” is the context for where the elements of hrbrthemes should be used.

    A “production workflow” is when you intend for the output of your work to be put into a publication of some kind, whether it be a blog post, academic paper, presentation, internal report or industry publication. When you’re cranking through an analysis, the visual elements don’t need to be perfect. They are there to validate/support your work and are more of a starting point for the finished product than anything else. The level of attention to detail on the final graphical products can be a great motivator for your audience to either dive deep into your analysis text or relegate it to the TLDR pile.

    @@ -94,7 +94,7 @@

    Kern-what?

    -

    Kerning is nothing more than a fancy word for spaces between letters and fonts have built-in tables for how various paris of letters should be placed next to each other. Great fonts have kerning tables that typography nerds immediately recognize and adore. Fonts with poor kerning tables are easily recognized as such by even the least font-aware viewer.

    +

    Kerning is nothing more than a fancy word for spaces between letters and fonts have built-in tables for how various pairs of letters should be placed next to each other. Great fonts have kerning tables that typography nerds immediately recognize and adore. Fonts with poor kerning tables are easily recognized as such by even the least font-aware viewer.


    https://www.xkcd.com/1015/

    diff --git a/man/gg_check.Rd b/man/gg_check.Rd index 09e6c80..568f019 100644 --- a/man/gg_check.Rd +++ b/man/gg_check.Rd @@ -4,15 +4,16 @@ \alias{gg_check} \title{Spell check ggplot2 plot labels} \usage{ -gg_check(gg, dict = hunspell::dictionary("en_US"), - ignore = hunspell::en_stats) +gg_check(gg, dict, ignore) } \arguments{ \item{gg}{ggplot2 object} -\item{dict}{a dictionary object or string which can be passed to \link[hunspell:dictionary]{hunspell::dictionary}} +\item{dict}{a dictionary object or string which can be passed to \link[hunspell:dictionary]{hunspell::dictionary}. +Defaults to \code{hunspell::dictionary("en_US")}} -\item{ignore}{character vector with additional approved words added to the dictionary} +\item{ignore}{character vector with additional approved words added to the dictionary. +Defaults to \code{hunspell::en_stats}} } \value{ the object that was passed in diff --git a/man/theme_ipsum.Rd b/man/theme_ipsum.Rd index 1e597f8..0dfaa2c 100644 --- a/man/theme_ipsum.Rd +++ b/man/theme_ipsum.Rd @@ -14,8 +14,8 @@ theme_ipsum(base_family = "Arial Narrow", base_size = 11, caption_size = 9, caption_face = "italic", caption_margin = 10, axis_title_family = subtitle_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", - plot_margin = margin(30, 30, 30, 30), grid = TRUE, axis = FALSE, - ticks = FALSE) + plot_margin = margin(30, 30, 30, 30), grid_col = "#cccccc", grid = TRUE, + axis_col = "#cccccc", axis = FALSE, ticks = FALSE) } \arguments{ \item{base_family, base_size}{base font family and size} @@ -36,6 +36,8 @@ theme_ipsum(base_family = "Arial Narrow", base_size = 11, \item{plot_margin}{plot margin (specify with \link[ggplot2:margin]{ggplot2::margin})} +\item{grid_col, axis_col}{grid & axis colors; both default to \code{#cccccc}} + \item{grid}{panel grid (\code{TRUE}, \code{FALSE}, or a combination of \code{X}, \code{x}, \code{Y}, \code{y})} \item{axis}{add x or y axes? \code{TRUE}, \code{FALSE}, "\code{xy}"} diff --git a/man/theme_ipsum_rc.Rd b/man/theme_ipsum_rc.Rd index f897d4a..42ae258 100644 --- a/man/theme_ipsum_rc.Rd +++ b/man/theme_ipsum_rc.Rd @@ -14,8 +14,8 @@ theme_ipsum_rc(base_family = "Roboto Condensed", base_size = 11, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", - plot_margin = margin(30, 30, 30, 30), grid = TRUE, axis = FALSE, - ticks = FALSE) + plot_margin = margin(30, 30, 30, 30), grid_col = "#2b2b2b99", + grid = TRUE, axis_col = "#2b2b2b", axis = FALSE, ticks = FALSE) } \arguments{ \item{base_family, base_size}{base font family and size} @@ -36,8 +36,12 @@ theme_ipsum_rc(base_family = "Roboto Condensed", base_size = 11, \item{plot_margin}{plot margin (specify with \link[ggplot2:margin]{ggplot2::margin})} +\item{grid_col}{grid color} + \item{grid}{panel grid (\code{TRUE}, \code{FALSE}, or a combination of \code{X}, \code{x}, \code{Y}, \code{y})} +\item{axis_col}{axis color} + \item{axis}{add x or y axes? \code{TRUE}, \code{FALSE}, "\code{xy}"} \item{ticks}{ticks if \code{TRUE} add ticks} diff --git a/tests/figs/deps.txt b/tests/figs/deps.txt new file mode 100644 index 0000000..7d787ff --- /dev/null +++ b/tests/figs/deps.txt @@ -0,0 +1,3 @@ +vdiffr: 0.1.1 +svglite: 1.2.0 +ggplot2: 2.2.1.9000 diff --git a/tests/figs/themes/theme-ipsum-rc.svg b/tests/figs/themes/theme-ipsum-rc.svg new file mode 100644 index 0000000..d235130 --- /dev/null +++ b/tests/figs/themes/theme-ipsum-rc.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 + + + + + +1.0 +1.5 +2.0 +2.5 +3.0 +1.0 +1.5 +2.0 +2.5 +3.0 +x +y +z + + +a +b +theme_ipsum_rc + diff --git a/tests/figs/themes/theme-ipsum.svg b/tests/figs/themes/theme-ipsum.svg new file mode 100644 index 0000000..4fe4ae9 --- /dev/null +++ b/tests/figs/themes/theme-ipsum.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 + + + + + +1.0 +1.5 +2.0 +2.5 +3.0 +1.0 +1.5 +2.0 +2.5 +3.0 +x +y +z + + +a +b +theme_ipsum + diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf deleted file mode 100644 index 8f47409..0000000 Binary files a/tests/testthat/Rplots.pdf and /dev/null differ diff --git a/tests/testthat/test-themes.R b/tests/testthat/test-themes.R new file mode 100644 index 0000000..0aa6ef9 --- /dev/null +++ b/tests/testthat/test-themes.R @@ -0,0 +1,13 @@ +context("themes") +test_that("themes are correct", { + + df <- data.frame(x = 1:3, y = 1:3, z = c("a", "b", "a"), a = 1) + + plot <- ggplot(df, aes(x, y, colour = z)) + + geom_point() + + facet_wrap(~ a) + + vdiffr::expect_doppelganger("theme_ipsum", plot + theme_ipsum()) + vdiffr::expect_doppelganger("theme_ipsum_rc", plot + theme_ipsum_rc()) + +}) \ No newline at end of file diff --git a/vignettes/why_hrbrthemes.Rmd b/vignettes/why_hrbrthemes.Rmd index d7edcb9..4e59f3e 100644 --- a/vignettes/why_hrbrthemes.Rmd +++ b/vignettes/why_hrbrthemes.Rmd @@ -54,7 +54,7 @@ If you work in a company, your communications department likely has a set of cor ### Kern-what? -[Kerning](https://en.wikipedia.org/wiki/Kerning) is nothing more than a fancy word for spaces between letters and fonts have built-in tables for how various paris of letters should be placed next to each other. Great fonts have kerning tables that typography nerds immediately recognize and adore. Fonts with poor kerning tables are easily recognized as such by even the least font-aware viewer. +[Kerning](https://en.wikipedia.org/wiki/Kerning) is nothing more than a fancy word for spaces between letters and fonts have built-in tables for how various pairs of letters should be placed next to each other. Great fonts have kerning tables that typography nerds immediately recognize and adore. Fonts with poor kerning tables are easily recognized as such by even the least font-aware viewer.