Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
^Rplots.pdf$
^vignettes/precompute_vignettes.R$
^vignettes/*.Rmd.orig$
^tests/testthat/test-with-pattern-treemapify\.R$
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Imports:
ggplot2 (>= 4.0.2),
glue,
grid,
gridpattern (>= 1.6.0),
gridpattern (>= 1.6.0-15),
lifecycle,
rlang (>= 1.1.3),
scales,
Expand All @@ -29,6 +29,7 @@ Suggests:
ambient,
dplyr,
gganimate,
hexbin,
knitr (>= 1.47),
magick,
mapproj,
Expand Down Expand Up @@ -66,13 +67,13 @@ Collate:
'geom-histogram.R'
'geom-polygon.R'
'geom-map.R'
'geom-point.R'
'geom-sf.R'
'geom-violin.R'
'ggpattern-defunct.R'
'ggpattern-deprecated.R'
'ggpattern-package.R'
'pattern.R'
'polygon_df.R'
'reexports.R'
'scale-pattern-alpha.R'
'scale-pattern-auto.R'
'scale-pattern-brewer.R'
Expand All @@ -86,6 +87,7 @@ Collate:
'scale-pattern-size.R'
'scale-pattern-viridis.R'
'scale-pattern.R'
'with-pattern.R'
'zxx.R'
'zzz.R'
Config/roxygen2/version: 8.0.0
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Generated by roxygen2: do not edit by hand

S3method(gridpattern::with_pattern,Layer)
S3method(gridpattern::with_pattern,dotstackGrob)
S3method(makeContent,ggpattern_area_mismatch_context)
S3method(makeContent,ggpattern_traced)
export(GeomAreaPattern)
export(GeomBarPattern)
export(GeomBin2dPattern)
Expand All @@ -8,15 +12,18 @@ export(GeomColPattern)
export(GeomCrossbarPattern)
export(GeomDensityPattern)
export(GeomMapPattern)
export(GeomPointPattern)
export(GeomPolygonPattern)
export(GeomRectPattern)
export(GeomRibbonPattern)
export(GeomSfPattern)
export(GeomTilePattern)
export(GeomViolinPattern)
export(create_polygon_df)
export(default_pattern_aes)
export(draw_key_boxplot_pattern)
export(draw_key_crossbar_pattern)
export(draw_key_point_pattern)
export(draw_key_polygon_pattern)
export(geom_area_pattern)
export(geom_bar_pattern)
Expand All @@ -28,13 +35,15 @@ export(geom_crossbar_pattern)
export(geom_density_pattern)
export(geom_histogram_pattern)
export(geom_map_pattern)
export(geom_point_pattern)
export(geom_polygon_pattern)
export(geom_rect_pattern)
export(geom_ribbon_pattern)
export(geom_sf_pattern)
export(geom_tile_pattern)
export(geom_violin_pattern)
export(is_polygon_df)
export(make_GeomPattern)
export(scale_pattern_alpha)
export(scale_pattern_alpha_continuous)
export(scale_pattern_alpha_discrete)
Expand Down Expand Up @@ -204,6 +213,9 @@ export(scale_pattern_yoffset_continuous)
export(scale_pattern_yoffset_discrete)
export(scale_pattern_yoffset_identity)
export(scale_pattern_yoffset_manual)
export(with_pattern)
export(with_pattern_aes)
export(with_pattern_key)
import(ggplot2)
import(glue)
import(grid)
Expand All @@ -214,6 +226,7 @@ importFrom(grDevices,col2rgb)
importFrom(grDevices,dev.off)
importFrom(grDevices,png)
importFrom(grDevices,rgb)
importFrom(gridpattern,with_pattern)
importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,deprecated)
importFrom(stats,setNames)
Expand Down
51 changes: 51 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,33 @@
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.

## Deprecated features

* `create_polygon_df()` and `is_polygon_df()` are (soft-)deprecated (#161)
since nothing exported accepts a `polygon_df`
(a data frame with `x`, `y`, and `id` columns).
To fill the areas of a grob with patterns see the new `with_pattern_aes()`.

## New features

* 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).
Its `area_by` argument says how the areas are matched to the rows of the data
(`"row"`, `"group"`, or a function) or else (by default for a geom we don't know)
each area is traced back to its row by the fill it was drawn with (`"trace"`).
Filling areas other than rectangles, polygons, and paths (e.g. circles or round rectangles) requires R (>= 4.2.0).
* We now re-export `gridpattern::with_pattern()` whose new `Layer` method makes a pattern layer from a layer
e.g. `with_pattern(geom_contour_filled(), pattern_fill = "white")`
(using our pattern geom for the layer's geom if we have one else `make_GeomPattern()`).
* New `with_pattern_aes()`, `with_pattern_key()`, and `default_pattern_aes()`
for writing the draw methods of a pattern geom (#156)
and a new "Developing Pattern Geoms" vignette.
* New `geom_point_pattern()` which fills each point with a filled symbol (`shape` 21 to 25, its default is 21)
with its own pattern (e.g. a different image per point using the "image" pattern and `pattern_filename`)
and its `draw_key_point_pattern()` legend key glyph.
Points with other shapes are drawn as by `geom_point()`.
Requires R (>= 4.2.0).
* New `pattern_linewidth` aesthetic for the stroke line width of patterns
(matching `{ggplot2}`'s renaming of the `size` aesthetic to `linewidth` for line widths)
with new `scale_pattern_linewidth()`, `scale_pattern_linewidth_continuous()`,
Expand All @@ -54,6 +79,32 @@

## Bug fixes and minor improvements

* Our geoms now draw the grob of the `{ggplot2}` geom they extend and fill each of its areas with a pattern in place
(using `gridpattern::with_pattern()`, #158)
instead of copying its grob-construction logic.
Each area keeps the pattern of its row (e.g. each bar, polygon group, or contiguous piece of a ribbon
gets its own gradient or image) and lines, points, and text (e.g. boxplot outliers, whiskers, and medians) are left alone.
Each area's fill, pattern, and border are now drawn in turn (like `{ggplot2}` draws its areas)
instead of every border being drawn above every pattern
so overlapping areas stack correctly and the border shared by neighbouring areas (e.g. tiles) is partly covered by the later area.
Requires `{gridpattern}` (>= 1.6.0-15).
* `draw_key_polygon_pattern()`, `draw_key_boxplot_pattern()`, and `draw_key_crossbar_pattern()`
now fill the area of `{ggplot2}`'s `draw_key_polygon()`, `draw_key_boxplot()`, and `draw_key_crossbar()` key glyphs
with a pattern (using `gridpattern::with_pattern()`, #158) instead of drawing their own glyphs.
So legend key borders now have the same width as the geom's borders (previously thinner),
the border of boxplot and crossbar keys is drawn above the pattern,
and boxplot and crossbar keys now respect `orientation` and the whisker, median, box, and staple graphical parameters.
* `geom_ribbon_pattern()`, `geom_area_pattern()`, and `geom_density_pattern()` now support a `fill` or `alpha`
that varies along the ribbon (drawn as a gradient by `{ggplot2}`) in linear coordinates.
Only the pattern aesthetics must be constant.
* The patterns of `geom_polygon_pattern()` polygons with a `subgroup` (i.e. holes) and of `geom_sf_pattern()`
are now positioned the same as those of other polygons
(their bounding box was previously measured in the wrong viewport).
* `geom_sf_pattern()` still draws one pattern per row (filling all the polygons of a `MULTIPOLYGON` as one region)
and now also fills each polygon of a `GEOMETRYCOLLECTION` (with the pattern of its row).
Each row's fill, pattern, and border are now drawn together (in row order like `{ggplot2}`)
and its lines and points are no longer edited (so e.g. closed arrow heads are no longer hollowed out).

* Bumps required version of `{gridpattern}` to v1.6.0:

+ This should fix a bug with patterns sometimes not showing up in the legend with larger `pattern_key_scale_factor` values (#86).
Expand Down
8 changes: 8 additions & 0 deletions R/a-geom-docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#' All geoms in this package are identical to their counterparts in ggplot2 except
#' that they can be filled with patterns.
#'
#' `geom_point_pattern()` fills each point with a filled symbol (`shape` 21 to 25, its default is 21)
#' with its own pattern (e.g. a different image per point) and requires R (>= 4.2.0).
#' Points with other shapes are drawn as by [ggplot2::geom_point()].
#' Pattern lengths (e.g. `pattern_spacing`) are relative to the plot panel by default
#' so for finer geometry patterns within (small) points use an absolute unit
#' e.g. `pattern_units = "mm"` with a small `pattern_spacing`.
#'
#' @section Pattern Arguments:
#'
#' Not all arguments apply to all patterns.
Expand Down Expand Up @@ -53,6 +60,7 @@
#' @inheritParams ggplot2::geom_crossbar
#' @inheritParams ggplot2::geom_histogram
#' @inheritParams ggplot2::geom_map
#' @inheritParams ggplot2::geom_point
#' @inheritParams ggplot2::geom_polygon
#' @inheritParams ggplot2::geom_rect
#' @inheritParams ggplot2::geom_ribbon
Expand Down
5 changes: 0 additions & 5 deletions R/aaa-ggplot2-compat-plyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

defaults <- function(x, y) c(x, y[setdiff(names(y), names(x))])

compact <- function(x) {
null <- vapply(x, is.null, logical(1))
x[!null]
}

#' Rename elements in a list, data.frame or vector
#'
#' This is akin to `dplyr::rename` and `plyr::rename`. It renames elements given
Expand Down
3 changes: 0 additions & 3 deletions R/aaa-ggplot2-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ binned_pal <- function(palette) {
}
}

# Wrapping vctrs data_frame constructor with no name repair
data_frame0 <- function(...) data_frame(..., .name_repair = "minimal")

# Wrapping unique0() to accept NULL
unique0 <- function(x, ...) if (is.null(x)) x else vec_unique(x, ...)
Loading
Loading