Skip to content

Commit 63c91b7

Browse files
authored
Update default aesthetics to ggplot2 4.0.0 from_theme() defaults (#211)
* bump version * replace default aes * add news bullet
1 parent b3483e6 commit 63c91b7

File tree

7 files changed

+49
-16
lines changed

7 files changed

+49
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ URL: https://github.com/teunbrand/ggh4x,
1818
https://teunbrand.github.io/ggh4x/
1919
BugReports: https://github.com/teunbrand/ggh4x/issues
2020
Depends:
21-
ggplot2 (>= 3.5.2)
21+
ggplot2 (>= 4.0.0)
2222
Imports:
2323
grid,
2424
gtable,

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggh4x (development version)
22

3+
* Incorporated `from_theme()` in many default aesthetics, allow the new layer
4+
defaults to be controlled from the theme (#210)
35
* New `save_plot()` function that wraps `ggsave()` but automatically defaults
46
its size to innate dimensions set by `force_panelsizes()` or the new
57
`theme(panel.widths, panel.heights)` settings (#187).

R/geom_box.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ GeomBox <- ggproto(
8484
"ymin", "ymax", "y", "height"),
8585

8686
default_aes = aes(
87-
colour = NA,
88-
fill = "grey35",
89-
linewidth = 0.5,
90-
linetype = 1,
87+
colour = from_theme(colour %||% NA),
88+
fill = from_theme(fill %||% col_mix(ink, paper, 0.35)),
89+
linewidth = from_theme(borderwidth),
90+
linetype = from_theme(bordertype),
9191
alpha = NA
9292
),
9393

R/geom_outline_point.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,13 @@ GeomOutlinePoint <- ggproto(
9999
"GeomOutlinePoint", GeomPoint,
100100

101101
default_aes = aes(
102-
shape = 16, colour = "grey50", size = 1.5, fill = NA,
103-
alpha = NA, stroke = 0.5, stroke_colour = "black"
102+
shape = from_theme(pointshape),
103+
colour = from_theme(colour %||% col_mix(ink, paper)),
104+
size = from_theme(pointsize),
105+
fill = from_theme(fill %||% NA),
106+
alpha = NA,
107+
stroke = from_theme(borderwidth),
108+
stroke_colour = from_theme(ink)
104109
),
105110

106111
draw_key = draw_key_outline_point,

R/geom_pointpath.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,15 @@ GeomPointPath <- ggplot2::ggproto(
126126
},
127127
# Adding some defaults for lines and mult
128128
default_aes = ggplot2::aes(
129-
shape = 19, colour = "black", size = 1.5, fill = NA, alpha = NA,
130-
stroke = 0.5, linewidth = 0.5, linetype = 1, mult = 0.5
129+
shape = from_theme(pointshape),
130+
colour = from_theme(colour %||% ink),
131+
size = from_theme(pointsize),
132+
fill = from_theme(fill %||% NA),
133+
alpha = NA,
134+
stroke = from_theme(borderwidth),
135+
linewidth = from_theme(linewidth),
136+
linetype = from_theme(linetype),
137+
mult = 0.5
131138
),
132139
non_missing_aes = c("size", "colour")
133140
)

R/geom_rectrug.R

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,13 @@ GeomRectMargin <- ggplot2::ggproto(
269269
grid::gTree(children = do.call(grid::gList, rugs))
270270
},
271271
optional_aes = c("x", "y", "xmin", "xmax", "ymin", "ymax"),
272-
default_aes = ggplot2::aes(colour = NA, fill = "grey35",
273-
linewidth = 0.5, linetype = 1, alpha = NA),
272+
default_aes = aes(
273+
colour = from_theme(colour %||% NA),
274+
fill = from_theme(fill %||% col_mix(ink, paper, 0.35)),
275+
linewidth = from_theme(borderwidth),
276+
linetype = from_theme(bordertype),
277+
alpha = NA
278+
),
274279
draw_key = ggplot2::draw_key_polygon
275280
)
276281

@@ -291,8 +296,14 @@ GeomTileMargin <- ggplot2::ggproto(
291296
ymin = y - height / 2, ymax = y + height / 2, height = NULL
292297
)
293298
},
294-
default_aes = ggplot2::aes(fill = "grey20", colour = NA,
295-
linewidth = 0.1, linetype = 1,
296-
alpha = NA, width = NA, height = NA),
299+
default_aes = aes(
300+
fill = from_theme(fill %||% col_mix(ink, paper, 0.2)),
301+
colour = from_theme(colour %||% NA),
302+
linewidth = from_theme(borderwidth / 5),
303+
linetype = from_theme(bordertype),
304+
alpha = NA,
305+
width = NA,
306+
height = NA
307+
),
297308
draw_key = ggplot2::draw_key_polygon
298309
)

R/geom_text_aimed.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,16 @@ geom_text_aimed <- function(
9393
GeomTextAimed <- ggproto(
9494
"GeomTextAimed", GeomText,
9595
default_aes = aes(
96-
colour = "black", size = 3.88, angle = 0, xend = -Inf, yend = -Inf,
97-
hjust = 0.5, vjust = 0.5, alpha = NA, family = "", fontface = 1,
96+
colour = from_theme(colour %||% ink),
97+
size = from_theme(fontsize),
98+
family = from_theme(family),
99+
angle = 0,
100+
xend = -Inf,
101+
yend = -Inf,
102+
hjust = 0.5,
103+
vjust = 0.5,
104+
alpha = NA,
105+
fontface = 1,
98106
lineheight = 1.2
99107
),
100108
draw_panel = function(data, panel_params, coord, parse = FALSE,

0 commit comments

Comments
 (0)