From 236da2c29b2a491ce5d31d7f09893b36cd67c854 Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Tue, 25 Feb 2020 11:44:53 -0500 Subject: [PATCH] x/y scales update to conform to new ggplot2 --- DESCRIPTION | 6 +-- NEWS.md | 4 ++ R/scales.r | 110 ++++++++++++++++++++++++++++++++++++------------- man/flush_ticks.Rd | 2 +- man/scale_ft.Rd | 12 +++--- man/scale_ipsum.Rd | 12 +++--- man/scale_x_percent.Rd | 22 ++++++---- man/theme_ipsum.Rd | 2 +- man/theme_ipsum_es.Rd | 2 +- man/theme_ipsum_ps.Rd | 2 +- man/theme_ipsum_pub.Rd | 2 +- man/theme_ipsum_rc.Rd | 2 +- man/theme_ipsum_tw.Rd | 2 +- 13 files changed, 123 insertions(+), 57 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8e8386b..1efbe48 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: hrbrthemes Type: Package Title: Additional Themes, Theme Components and Utilities for 'ggplot2' -Version: 0.7.2 -Date: 2019-08-08 +Version: 0.8.0 +Date: 2020-02-25 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")), @@ -57,5 +57,5 @@ Imports: tools, magrittr, gdtools -RoxygenNote: 7.0.0 +RoxygenNote: 7.0.2 VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 94d390e..9c31e8b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# hrbrthemes 0.8.0 + +- Changes to conform to forthcoming {ggplot2} release + # hrbrthemes 0.7.2 - Further enhancements to the `scale_[xy]_… functions` to support passing in diff --git a/R/scales.r b/R/scales.r index f7c5039..5e91162 100644 --- a/R/scales.r +++ b/R/scales.r @@ -45,13 +45,26 @@ is.formula <- function (x) { inherits(x, "formula") } #' scales, "top" or "bottom" for horizontal scales #' @param sec.axis specify a secondary axis #' @export -scale_x_percent <- function(name = waiver(), breaks = waiver(), +scale_x_percent <- function(name = waiver(), + breaks = waiver(), minor_breaks = waiver(), - limits = NULL, expand = c(0.01,0), oob = censor, - na.value = NA_real_, trans = "identity", - position = "bottom", sec.axis = waiver(), labels, - accuracy = 1, scale = 100, prefix = "", suffix = "%", - big.mark = " ", decimal.mark = ".", trim = TRUE, ...) { + guide = waiver(), + n.breaks = NULL, + labels, + limits = NULL, + expand = c(0.01,0), + oob = censor, + na.value = NA_real_, + trans = "identity", + position = "bottom", + sec.axis = waiver(), + accuracy = 1, + scale = 100, + prefix = "", + suffix = "%", + big.mark = " ", + decimal.mark = ".", + trim = TRUE, ...) { if (missing(labels)) { scales::percent_format( @@ -69,12 +82,13 @@ scale_x_percent <- function(name = waiver(), breaks = waiver(), ggplot2::continuous_scale( aesthetics = c( "x", "xmin", "xmax", "xend", "xintercept", "xmin_final", - "xmax_final", "xlower", "xmiddle", "xupper" + "xmax_final", "xlower", "xmiddle", "xupper", "x0" ), scale_name = "position_c", palette = identity, name = name, breaks = breaks, + n.breaks = n.breaks, minor_breaks = minor_breaks, labels = labels, limits = limits, @@ -82,7 +96,7 @@ scale_x_percent <- function(name = waiver(), breaks = waiver(), oob = oob, na.value = na.value, trans = trans, - guide = "none", + guide = guide, position = position, super = ScaleContinuousPosition ) -> sc @@ -102,13 +116,26 @@ scale_x_percent <- function(name = waiver(), breaks = waiver(), #' @rdname scale_x_percent #' @export -scale_y_percent <- function(name = waiver(), breaks = waiver(), +scale_y_percent <- function(name = waiver(), + breaks = waiver(), minor_breaks = waiver(), - limits = NULL, expand = c(0.01,0), oob = censor, - na.value = NA_real_, trans = "identity", - position = "left", sec.axis = waiver(), labels, - accuracy = 1, scale = 100, prefix = "", suffix = "%", - big.mark = " ", decimal.mark = ".", trim = TRUE, ...) { + guide = waiver(), + n.breaks = NULL, + labels, + limits = NULL, + expand = c(0.01,0), + oob = censor, + na.value = NA_real_, + trans = "identity", + position = "left", + sec.axis = waiver(), + accuracy = 1, + scale = 100, + prefix = "", + suffix = "%", + big.mark = " ", + decimal.mark = ".", + trim = TRUE, ...) { if (missing(labels)) { scales::percent_format( @@ -132,6 +159,7 @@ scale_y_percent <- function(name = waiver(), breaks = waiver(), palette = identity, name = name, breaks = breaks, + n.breaks = n.breaks, minor_breaks = minor_breaks, labels = labels, limits = limits, @@ -139,7 +167,7 @@ scale_y_percent <- function(name = waiver(), breaks = waiver(), oob = oob, na.value = na.value, trans = trans, - guide = "none", + guide = guide, position = position, super = ScaleContinuousPosition ) -> sc @@ -162,14 +190,26 @@ scale_y_percent <- function(name = waiver(), breaks = waiver(), #' [scales::comma_format()] or [scales::percent_format()] #' @param ... passed on to [scales::comma_format()] or [scales::percent_format()] #' @export -scale_x_comma <- function(name = waiver(), breaks = waiver(), +scale_x_comma <- function(name = waiver(), + breaks = waiver(), minor_breaks = waiver(), + guide = waiver(), + n.breaks = NULL, + labels, limits = NULL, - expand = c(0.01,0), oob = censor, - na.value = NA_real_, trans = "identity", - position = "bottom", sec.axis = waiver(), labels, - accuracy = 1, scale = 1, prefix = "", suffix = "", - big.mark = ",", decimal.mark = ".", trim = TRUE, + expand = c(0.01,0), + oob = censor, + na.value = NA_real_, + trans = "identity", + position = "bottom", + sec.axis = waiver(), + accuracy = 1, + scale = 1, + prefix = "", + suffix = "", + big.mark = ",", + decimal.mark = ".", + trim = TRUE, ...) { if (missing(labels)) { @@ -195,6 +235,7 @@ scale_x_comma <- function(name = waiver(), breaks = waiver(), palette = identity, name = name, breaks = breaks, + n.breaks = n.breaks, minor_breaks = minor_breaks, labels = labels, limits = limits, @@ -202,7 +243,7 @@ scale_x_comma <- function(name = waiver(), breaks = waiver(), oob = oob, na.value = na.value, trans = trans, - guide = "none", + guide = guide, position = position, super = ScaleContinuousPosition ) -> sc @@ -225,11 +266,23 @@ scale_x_comma <- function(name = waiver(), breaks = waiver(), scale_y_comma <- function(name = waiver(), breaks = waiver(), minor_breaks = waiver(), - limits = NULL, expand = c(0.01,0), oob = censor, - na.value = NA_real_, trans = "identity", - position = "left", sec.axis = waiver(), labels, - accuracy = 1, scale = 1, prefix = "", suffix = "", - big.mark = ",", decimal.mark = ".", trim = TRUE, + guide = waiver(), + n.breaks = NULL, + labels, + limits = NULL, + expand = c(0.01,0), + oob = censor, + na.value = NA_real_, + trans = "identity", + position = "left", + sec.axis = waiver(), + accuracy = 1, + scale = 1, + prefix = "", + suffix = "", + big.mark = ",", + decimal.mark = ".", + trim = TRUE, ...) { if (missing(labels)) { @@ -255,6 +308,7 @@ scale_y_comma <- function(name = waiver(), palette = identity, name = name, breaks = breaks, + n.breaks = n.breaks, minor_breaks = minor_breaks, labels = labels, limits = limits, @@ -262,7 +316,7 @@ scale_y_comma <- function(name = waiver(), oob = oob, na.value = na.value, trans = trans, - guide = "none", + guide = guide, position = position, super = ScaleContinuousPosition ) -> sc diff --git a/man/flush_ticks.Rd b/man/flush_ticks.Rd index 0fb6c9d..0c994e3 100644 --- a/man/flush_ticks.Rd +++ b/man/flush_ticks.Rd @@ -22,7 +22,7 @@ ggplot2 object with \code{theme()} elements added A covenience function intended for basic, fixed-scale plots only (i.e. does not handle free scales in facets).\cr \cr -You need to pass in a ggplot2 object to this function. It can't be \verb{+}'d in a chain +You need to pass in a ggplot2 object to this function. It can't be \code{+}'d in a chain of geoms, coords, scales, themes, etc. It also builds the plot (but does not display it) so if the plt takes a while (i.e. has lots of data or transforms) this will also take a while. diff --git a/man/scale_ft.Rd b/man/scale_ft.Rd index e9581fd..28577e2 100644 --- a/man/scale_ft.Rd +++ b/man/scale_ft.Rd @@ -16,11 +16,12 @@ scale_fill_ft(...) \item{...}{ Arguments passed on to \code{\link[ggplot2:discrete_scale]{ggplot2::discrete_scale}} \describe{ - \item{\code{aesthetics}}{The names of the aesthetics that this scale works with} - \item{\code{scale_name}}{The name of the scale} + \item{\code{aesthetics}}{The names of the aesthetics that this scale works with.} + \item{\code{scale_name}}{The name of the scale that should be used for error messages +associated with this scale.} \item{\code{palette}}{A palette function that when called with a single integer argument (the number of levels in the scale) returns the values that -they should take.} +they should take (e.g., \code{\link[scales:hue_pal]{scales::hue_pal()}}).} \item{\code{name}}{The name of the scale. Used as the axis or legend title. If \code{waiver()}, the default, the name of the scale is taken from the first mapping used for that aesthetic. If \code{NULL}, the legend title will be @@ -28,8 +29,7 @@ omitted.} \item{\code{breaks}}{One of: \itemize{ \item \code{NULL} for no breaks -\item \code{waiver()} for the default breaks computed by the -transformation object +\item \code{waiver()} for the default breaks (the scale limits) \item A character vector of breaks \item A function that takes the limits as input and returns breaks as output @@ -55,7 +55,7 @@ where \code{NA} is always placed at the far right.} The default, \code{TRUE}, uses the levels that appear in the data; \code{FALSE} uses all the levels in the factor.} \item{\code{guide}}{A function used to create a guide or its name. See -\code{\link[=guides]{guides()}} for more info.} +\code{\link[ggplot2:guides]{guides()}} for more information.} \item{\code{super}}{The super class to use for the constructed scale} }} } diff --git a/man/scale_ipsum.Rd b/man/scale_ipsum.Rd index 97912c4..d25d3d9 100644 --- a/man/scale_ipsum.Rd +++ b/man/scale_ipsum.Rd @@ -16,11 +16,12 @@ scale_fill_ipsum(...) \item{...}{ Arguments passed on to \code{\link[ggplot2:discrete_scale]{ggplot2::discrete_scale}} \describe{ - \item{\code{aesthetics}}{The names of the aesthetics that this scale works with} - \item{\code{scale_name}}{The name of the scale} + \item{\code{aesthetics}}{The names of the aesthetics that this scale works with.} + \item{\code{scale_name}}{The name of the scale that should be used for error messages +associated with this scale.} \item{\code{palette}}{A palette function that when called with a single integer argument (the number of levels in the scale) returns the values that -they should take.} +they should take (e.g., \code{\link[scales:hue_pal]{scales::hue_pal()}}).} \item{\code{name}}{The name of the scale. Used as the axis or legend title. If \code{waiver()}, the default, the name of the scale is taken from the first mapping used for that aesthetic. If \code{NULL}, the legend title will be @@ -28,8 +29,7 @@ omitted.} \item{\code{breaks}}{One of: \itemize{ \item \code{NULL} for no breaks -\item \code{waiver()} for the default breaks computed by the -transformation object +\item \code{waiver()} for the default breaks (the scale limits) \item A character vector of breaks \item A function that takes the limits as input and returns breaks as output @@ -55,7 +55,7 @@ where \code{NA} is always placed at the far right.} The default, \code{TRUE}, uses the levels that appear in the data; \code{FALSE} uses all the levels in the factor.} \item{\code{guide}}{A function used to create a guide or its name. See -\code{\link[=guides]{guides()}} for more info.} +\code{\link[ggplot2:guides]{guides()}} for more information.} \item{\code{super}}{The super class to use for the constructed scale} }} } diff --git a/man/scale_x_percent.Rd b/man/scale_x_percent.Rd index e78ba5d..4959a1a 100644 --- a/man/scale_x_percent.Rd +++ b/man/scale_x_percent.Rd @@ -11,6 +11,9 @@ scale_x_percent( name = waiver(), breaks = waiver(), minor_breaks = waiver(), + guide = waiver(), + n.breaks = NULL, + labels, limits = NULL, expand = c(0.01, 0), oob = censor, @@ -18,7 +21,6 @@ scale_x_percent( trans = "identity", position = "bottom", sec.axis = waiver(), - labels, accuracy = 1, scale = 100, prefix = "", @@ -33,6 +35,9 @@ scale_y_percent( name = waiver(), breaks = waiver(), minor_breaks = waiver(), + guide = waiver(), + n.breaks = NULL, + labels, limits = NULL, expand = c(0.01, 0), oob = censor, @@ -40,7 +45,6 @@ scale_y_percent( trans = "identity", position = "left", sec.axis = waiver(), - labels, accuracy = 1, scale = 100, prefix = "", @@ -55,6 +59,9 @@ scale_x_comma( name = waiver(), breaks = waiver(), minor_breaks = waiver(), + guide = waiver(), + n.breaks = NULL, + labels, limits = NULL, expand = c(0.01, 0), oob = censor, @@ -62,7 +69,6 @@ scale_x_comma( trans = "identity", position = "bottom", sec.axis = waiver(), - labels, accuracy = 1, scale = 1, prefix = "", @@ -77,6 +83,9 @@ scale_y_comma( name = waiver(), breaks = waiver(), minor_breaks = waiver(), + guide = waiver(), + n.breaks = NULL, + labels, limits = NULL, expand = c(0.01, 0), oob = censor, @@ -84,7 +93,6 @@ scale_y_comma( trans = "identity", position = "left", sec.axis = waiver(), - labels, accuracy = 1, scale = 1, prefix = "", @@ -120,6 +128,9 @@ each major break) \item A function that given the limits returns a vector of minor breaks. }} +\item{labels}{Specifying overrides the default format (i.e. you really don't +want to do that). \code{NULL} means no labels.} + \item{limits}{A numeric vector of length two providing limits of the scale. Use \code{NA} to refer to the existing minimum or maximum.} @@ -142,9 +153,6 @@ scales, "top" or "bottom" for horizontal scales} \item{sec.axis}{specify a secondary axis} -\item{labels}{Specifying overrides the default format (i.e. you really don't -want to do that). \code{NULL} means no labels.} - \item{accuracy, scale, prefix, suffix, big.mark, decimal.mark, trim}{See [scales::comma_format()] or [scales::percent_format()]} diff --git a/man/theme_ipsum.Rd b/man/theme_ipsum.Rd index 7b97ab5..c7cb5f8 100644 --- a/man/theme_ipsum.Rd +++ b/man/theme_ipsum.Rd @@ -113,7 +113,7 @@ ggplot(mtcars, aes(mpg, wt)) + update_geom_font_defaults() -count(mpg, class) %>% +count(mpg, class) \%>\% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + diff --git a/man/theme_ipsum_es.Rd b/man/theme_ipsum_es.Rd index f2c493e..48fdbe0 100644 --- a/man/theme_ipsum_es.Rd +++ b/man/theme_ipsum_es.Rd @@ -106,7 +106,7 @@ ggplot(mtcars, aes(mpg, wt)) + # note: may need to make this font_es on Windows update_geom_font_defaults(family=font_es_light) -count(mpg, class) %>% +count(mpg, class) \%>\% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + diff --git a/man/theme_ipsum_ps.Rd b/man/theme_ipsum_ps.Rd index e2faa3c..68447a9 100644 --- a/man/theme_ipsum_ps.Rd +++ b/man/theme_ipsum_ps.Rd @@ -103,7 +103,7 @@ ggplot(mtcars, aes(mpg, wt)) + # note: make this font_rc on Windows update_geom_font_defaults(family=font_rc_light) -count(mpg, class) %>% +count(mpg, class) \%>\% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + diff --git a/man/theme_ipsum_pub.Rd b/man/theme_ipsum_pub.Rd index ffd18f4..f3919e0 100644 --- a/man/theme_ipsum_pub.Rd +++ b/man/theme_ipsum_pub.Rd @@ -103,7 +103,7 @@ ggplot(mtcars, aes(mpg, wt)) + update_geom_font_defaults(family=font_pub) -count(mpg, class) %>% +count(mpg, class) \%>\% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + diff --git a/man/theme_ipsum_rc.Rd b/man/theme_ipsum_rc.Rd index 0a238a2..9381216 100644 --- a/man/theme_ipsum_rc.Rd +++ b/man/theme_ipsum_rc.Rd @@ -170,7 +170,7 @@ ggplot(mtcars, aes(mpg, wt)) + # note: make this font_rc on Windows update_geom_font_defaults(family=font_rc_light) -count(mpg, class) %>% +count(mpg, class) \%>\% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + diff --git a/man/theme_ipsum_tw.Rd b/man/theme_ipsum_tw.Rd index 14efb07..f2da1da 100644 --- a/man/theme_ipsum_tw.Rd +++ b/man/theme_ipsum_tw.Rd @@ -104,7 +104,7 @@ ggplot(mtcars, aes(mpg, wt)) + # note: make this font_rc on Windows update_geom_font_defaults(family=font_rc_light) -count(mpg, class) %>% +count(mpg, class) \%>\% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) +