Skip to content
Browse files

Allow color bars to show expressions from formatters

  • Loading branch information...
1 parent f2f5e8c commit 1567d9d76bd752b9f692127317739bd705a8da84 @wch wch committed
Showing with 12 additions and 1 deletion.
  1. +12 −1 R/guide-colorbar.r
View
13 R/guide-colorbar.r
@@ -293,7 +293,18 @@ guide_gengrob.colorbar <- function(guide, theme) {
vjust <- y <- guide$label.vjust %||% 0.5
switch(guide$direction, horizontal = {x <- label_pos; y <- vjust}, "vertical" = {x <- hjust; y <- label_pos})
- g <- element_grob(element = label.theme, label = guide$key$.label,
+ label <- guide$key$.label
+
+ # If any of the labels are quoted language objects, convert them
+ # to expressions. Labels from formatter functions can return these
+ if (any(vapply(label, is.call, logical(1)))) {
+ label <- lapply(label, function(l) {
+ if (is.call(l)) substitute(expression(x), list(x = l))
+ else l
+ })
+ label <- do.call(c, label)
+ }
+ g <- element_grob(element = label.theme, label = label,
x = x, y = y, hjust = hjust, vjust = vjust)
ggname("guide.label", g)
}

0 comments on commit 1567d9d

Please sign in to comment.
Something went wrong with that request. Please try again.