Skip to content
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

Colour rings #10

Merged
merged 15 commits into from
Apr 27, 2024
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(GizmoDensity)
export(GizmoGrob)
export(GizmoHistogram)
export(GizmoStepcap)
export(GuideColourRing)
export(GuideSubtitle)
export(PrimitiveBox)
export(PrimitiveBracket)
Expand Down Expand Up @@ -40,6 +41,7 @@ export(gizmo_grob)
export(gizmo_histogram)
export(gizmo_stepcap)
export(guide_axis_custom)
export(guide_colour_ring)
export(guide_colourbar_custom)
export(guide_coloursteps_custom)
export(guide_subtitle)
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Full guides are guides that you can just drop in the `guides()` function or as
`guide` argument to scales.

* `guide_axis_custom()` as an axis guide.
* `guide_colourbar_custom()` as a colour/fill guide.
* `guide_coloursteps_custom()` as a colour/fill guide.
* `guide_colourbar_custom()` as a continuous colour/fill guide.
* `guide_coloursteps_custom()` as a binned colour/fill guide.
* `guide_colour_ring()` as a continuous colour/fill guide.
* `guide_subtitle()` as a colour/fill guide.

## Gizmos
Expand Down
5 changes: 3 additions & 2 deletions R/compose-.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Compose <- ggproto(
aesthetic <- params$aesthetic <- aesthetic %||% scale$aesthetics[1]
check_position(position, allow_null = TRUE)

key <- params$key
key <- resolve_key(params$key, allow_null = TRUE)
if (is.function(key)) {
key <- key(scale, aesthetic %||% scale$aesthetics[1])
}
Expand All @@ -86,7 +86,8 @@ Compose <- ggproto(
} else {
guide_title <- waiver()
}
guide_params[[i]]$position <- position
guide_params[[i]]$position <-
(guide_params[[i]]$position %|W|% NULL) %||% position
guide_params[[i]]$angle <- guide_params[[i]]$angle %|W|% params$angle
guide_params[[i]]["key"] <- list(guide_params[[i]]$key %||% key)
guide_params[[i]] <- params$guides[[i]]$train(
Expand Down
2 changes: 1 addition & 1 deletion R/compose-ontop.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ComposeOntop <- ggproto(
guide_index <- seq_len(n_guides)
grobs <- vector("list", n_guides)

if (position %in% c("theta", "theta.sec")) {
if (is_theta(position)) {
stack_offset <- unit(cm(params$stack_offset %||% 0), "cm")
offset <- stack_offset

Expand Down
20 changes: 11 additions & 9 deletions R/compose-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ComposeStack <- ggproto(
},

override_elements = function(params, elements, theme) {
if (!params$position %in% c("theta", "theta.sec")) {
if (!is_theta(params$position)) {
elements$spacing <- cm(elements$spacing)
}
if (!is.null(params$side_titles)) {
Expand Down Expand Up @@ -154,14 +154,23 @@ ComposeStack <- ggproto(

guide_index <- seq_len(n_guides)
grobs <- vector("list", n_guides)
draw_label <- !isFALSE(params$draw_label %||% TRUE)

keep <- rep(TRUE, n_guides)
if (!draw_label && length(params$drop) > 0) {
drop <- intersect(params$drop %||% guide_index[-1], guide_index)
keep[drop] <- FALSE
}

if (position %in% c("theta", "theta.sec")) {
if (is_theta(position)) {
stack_offset <- unit(cm(params$stack_offset %||% 0), "cm")
offset <- stack_offset
offset_ranges <- vector("list", n_guides)
guide_index <- guide_index[keep]

for (i in guide_index) {
pars <- params$guide_params[[i]]
pars$draw_label <- params$draw_label
pars$stack_offset <- offset
grob <- params$guides[[i]]$draw(
theme = theme, position = position, direction = direction,
Expand All @@ -188,13 +197,6 @@ ComposeStack <- ggproto(

side_titles <- self$build_title(params$side_titles, elems, params)

keep <- rep(TRUE, n_guides)
draw_label <- !isFALSE(params$draw_label %||% TRUE)
if (!draw_label && length(params$drop) > 0) {
drop <- intersect(params$drop %||% guide_index[-1], guide_index)
keep[drop] <- FALSE
}

for (i in guide_index) {
pars <- params$guide_params[[i]]
pars$draw_label <- draw_label
Expand Down
Loading
Loading