Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ggpattern
Type: Package
Title: 'ggplot2' Pattern Geoms
Version: 1.4.0-6
Version: 1.4.0-7
Authors@R: c(person("Mike", "FC", role = "aut"),
person("Trevor L.", "Davis", role = c("aut", "cre"),
email = "trevor.l.davis@gmail.com",
Expand Down Expand Up @@ -88,6 +88,7 @@ Collate:
'scale-pattern-hue.R'
'scale-pattern-linetype.R'
'scale-pattern-linewidth.R'
'scale-pattern-palette.R'
'scale-pattern-shape.R'
'scale-pattern-size.R'
'scale-pattern-viridis.R'
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,4 @@ importFrom(gridpattern,with_pattern)
importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,deprecated)
importFrom(stats,setNames)
importFrom(utils,head)
importFrom(utils,tail)
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
* An `NA` value of an aesthetic is now always passed on to `{gridpattern}` where it may be meaningful
e.g. an `NA` `pattern_fill2` is now a transparent colour (previously replaced by the default `pattern_fill2`)
and an `NA` `pattern_shape` still draws nothing for the "pch" pattern.
* The `choices` and `range` arguments of our `scale_pattern_*_discrete()` and `scale_pattern_*_continuous()` scales
and of `scale_pattern_alpha_ordinal()`, `scale_pattern_linewidth_ordinal()`, and `scale_pattern_size_ordinal()`
(and the `solid` argument of `scale_pattern_shape()`) now default to `NULL`
which uses the scale's `palette.<aesthetic>.<type>` theme element if set else the previous default (#172).
A `NULL` `choices` or `range` is no longer an error when the scale is made;
a scale without a default palette (e.g. `scale_pattern_type_discrete()`) instead throws an error
when it is used without a `choices`, `range`, `palette`, or theme palette.
`scale_pattern_colour_discrete()`, `scale_pattern_fill_discrete()`, and `scale_pattern_fill2_discrete()`
are no longer aliases of the `scale_pattern_*_hue()` scales (though they still accept their arguments)
and the `type` of `scale_pattern_colour_continuous()`, `scale_pattern_fill_continuous()`,
and `scale_pattern_fill2_continuous()` now defaults to `NULL` (previously `"gradient"` when the option was unset).
The default palettes are unchanged.

## Deprecated features

Expand All @@ -45,6 +57,16 @@

## New features

* Our `scale_pattern_*_discrete()` and `scale_pattern_*_continuous()` scales
(and `scale_pattern_alpha_ordinal()`, `scale_pattern_linewidth_ordinal()`, `scale_pattern_size_ordinal()`,
`scale_pattern_linetype()`, and `scale_pattern_shape()`) have a new `palette` argument (#172)
e.g. `scale_pattern_type_discrete(palette = c("hexagonal", "rhombille", "pythagorean"))`.
It takes precedence over `choices` or `range`.
* Like `{ggplot2}`'s own scales these scales now look up their palette in the
`palette.<aesthetic>.discrete` or `palette.<aesthetic>.continuous` theme element when not given one
e.g. `theme(palette.pattern_type.discrete = c("hexagonal", "rhombille", "pythagorean"))` (#172).
We register these theme elements for every pattern aesthetic with a scale when `{ggpattern}` is loaded
(see `?pattern_palettes`).
* New `make_GeomPattern()` makes a pattern geom from (almost) any `{ggplot2}` (or extension) geom:
it draws the geom's grob and fills each of its areas with the pattern of its row
(use `ggplot2::make_constructor()` to make its `geom_*_pattern()` function).
Expand Down
17 changes: 13 additions & 4 deletions R/scale-pattern-alpha.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#' or [ggplot2::discrete_scale()] as appropriate, to control name, limits,
#' breaks, labels and so forth.
#' @param range Output range of alpha values. Must lie between 0 and 1.
#' If `NULL` (and `palette` is `NULL`) uses the `palette.pattern_alpha.<type>` theme element
#' (see [pattern_palettes]) else `c(0.1, 1)`.
#' @param palette A palette function e.g. [scales::pal_rescale()] for a continuous scale
#' or a `function(n)` returning `n` values for a discrete scale. Takes precedence over `range`.
#' For a vector of values use `range` or [scale_pattern_alpha_manual()].
#' @examples
#' if (require("ggplot2")) {
#' # 'stripe' pattern example
Expand All @@ -34,8 +39,11 @@
#' @return A [ggplot2::Scale] object.
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scale_pattern_alpha_continuous <- function(..., range = c(0.1, 1)) {
continuous_scale("pattern_alpha", palette = rescale_pal(range), ...)
scale_pattern_alpha_continuous <- function(..., range = NULL, palette = NULL) {
continuous_scale("pattern_alpha",
palette = as_scale_palette(palette, range, rescale_pal, "continuous", "pattern_alpha", "range"),
fallback.palette = rescale_pal(c(0.1, 1)),
...)
}

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -65,10 +73,11 @@ scale_pattern_alpha_discrete <- function(...) {
#' @rdname scale_pattern_alpha_continuous
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scale_pattern_alpha_ordinal <- function(..., range = c(0.1, 1)) {
scale_pattern_alpha_ordinal <- function(..., range = NULL, palette = NULL) {
discrete_scale(
"pattern_alpha",
palette = function(n) seq(range[1], range[2], length.out = n),
palette = as_scale_palette(palette, range, pal_seq_range, "discrete", "pattern_alpha", "range"),
fallback.palette = pal_seq_range(c(0.1, 1)),
...
)
}
Expand Down
Loading
Loading