Skip to content

Orientation-aware key glyphs #4757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 23, 2022
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
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 @@ -67,6 +67,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