Skip to content

Commit

Permalink
Orientation-aware key glyphs (#4757)
Browse files Browse the repository at this point in the history
Fixes #4732
  • Loading branch information
mjskay committed Mar 23, 2022
1 parent afc03e0 commit 0e64d9c
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export(draw_key_boxplot)
export(draw_key_crossbar)
export(draw_key_dotplot)
export(draw_key_label)
export(draw_key_linerange)
export(draw_key_path)
export(draw_key_point)
export(draw_key_pointrange)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ precedence between `bins` and `binwidth`. (@eliocamp, #4651)
* Dots in `geom_dotplot()` are now correctly aligned to the baseline when
`stackratio != 1` and `stackdir != "up"` (@mjskay, #4614)

* Key glyphs for `geom_boxplot()`, `geom_crossbar()`, `geom_pointrange()`, and
`geom_linerange()` are now orientation-aware (@mjskay, #4732)

# ggplot2 3.3.5
This is a very small release focusing on fixing a couple of untenable issues
that surfaced with the 3.3.4 release
Expand Down
2 changes: 1 addition & 1 deletion R/geom-linerange.r
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ geom_linerange <- function(mapping = NULL, data = NULL,
GeomLinerange <- ggproto("GeomLinerange", Geom,
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),

draw_key = draw_key_vpath,
draw_key = draw_key_linerange,

required_aes = c("x|y", "ymin|xmin", "ymax|xmax"),

Expand Down
18 changes: 15 additions & 3 deletions R/legend-draw.r
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ draw_key_boxplot <- function(data, params, size) {
lty = data$linetype %||% 1,
lineend = params$lineend %||% "butt",
linejoin = params$linejoin %||% "mitre"
)
),
vp = if (isTRUE(params$flipped_aes)) viewport(angle = -90)
)
}

Expand All @@ -123,7 +124,8 @@ draw_key_crossbar <- function(data, params, size) {
lty = data$linetype %||% 1,
lineend = params$lineend %||% "butt",
linejoin = params$linejoin %||% "mitre"
)
),
vp = if (isTRUE(params$flipped_aes)) viewport(angle = -90)
)
}

Expand Down Expand Up @@ -177,11 +179,21 @@ draw_key_dotplot <- function(data, params, size) {
)
}

#' @export
#' @rdname draw_key
draw_key_linerange <- function(data, params, size) {
if (isTRUE(params$flipped_aes)) {
draw_key_path(data, params, size)
} else {
draw_key_vpath(data, params, size)
}
}

#' @export
#' @rdname draw_key
draw_key_pointrange <- function(data, params, size) {
grobTree(
draw_key_vpath(data, params, size),
draw_key_linerange(data, params, size),
draw_key_point(transform(data, size = (data$size %||% 1.5) * 4), params)
)
}
Expand Down
3 changes: 3 additions & 0 deletions man/draw_key.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions tests/testthat/_snaps/draw-key/horizontal-boxplot-and-crossbar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0e64d9c

Please sign in to comment.