Skip to content

Commit 082641a

Browse files
committed
Add support for ggplot2 3.5 patterns and gradients
- See https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-0/#patterns-and-gradients - #50, thanks @trevorld
1 parent 1df099e commit 082641a

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BugReports: https://github.com/wilkox/treemapify/issues/
1212
Description: Provides 'ggplot2' geoms for drawing treemaps.
1313
Depends: R (>= 3.6)
1414
Imports:
15-
ggplot2 (>= 2.2.1),
15+
ggplot2 (>= 3.5),
1616
ggfittext (>= 0.5.0),
1717
grid (>= 3.1),
1818
cli (>= 3.6.1)

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# treemapify (development version)
22

3+
## Major changes
4+
5+
- Add support for ggplot2 3.5 patterns and gradients (see
6+
https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-0/#patterns-and-gradients;
7+
#50, thanks @trevorld)
8+
39
## Minor changes
410

511
- Change default roundrect radius in GeomTreemap to 0 pts (#48, thanks @davidhodge931)

R/a-rect.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ GeomRrect <- ggplot2::ggproto(
4747
just = c("left", "top"),
4848
gp = grid::gpar(
4949
col = coords$colour[i],
50-
fill = alpha(coords$fill[i], coords$alpha[i]),
50+
fill = ggplot2::fill_alpha(coords$fill[i], coords$alpha[i]),
5151
lwd = coords$size[i] * .pt,
5252
lty = coords$linetype[i],
5353
lineend = "butt"

R/geom_treemap.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ draw_key_rrect <- function(data, params, size) {
134134
name = "lkey",
135135
gp = grid::gpar(
136136
col = data$colour %l0% "white",
137-
fill = alpha(data$fill %||% data$colour %||% "grey20", data$alpha),
137+
fill = ggplot2::fill_alpha(data$fill %||% data$colour %||% "grey20", data$alpha),
138138
lty = data$linetype %||% 1
139139
)
140140
)
@@ -197,7 +197,7 @@ GeomTreemap <- ggplot2::ggproto(
197197
just = c("left", "top"),
198198
gp = grid::gpar(
199199
col = data$colour[i],
200-
fill = ggplot2::alpha(data$fill[i], data$alpha[i]),
200+
fill = ggplot2::fill_alpha(data$fill[i], data$alpha[i]),
201201
lwd = data$size[i],
202202
lty = data$linetype[i]
203203
)

tests/testthat/test_plots.R

+14
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,18 @@ test_that("plots look the way they should", {
105105
list(color = c("red", "black"))))
106106
})
107107

108+
# vdiffr does not support patterns
109+
expect_no_error({
110+
patterns <- list(
111+
linearGradient(c("red", "blue"), group = FALSE),
112+
linearGradient(c("yellow", "orange"), group = FALSE),
113+
linearGradient(c("purple", "white"), group = FALSE),
114+
linearGradient(c("pink", "green"), group = FALSE)
115+
)
116+
G4 <- G20[1:4, ]
117+
ggplot2::ggplot(G4, ggplot2::aes(area = gdp_mil_usd, fill = country)) +
118+
geom_treemap() +
119+
ggplot2::scale_fill_manual(values = patterns)
120+
})
121+
108122
})

0 commit comments

Comments
 (0)