Skip to content

Commit 1d537ce

Browse files
brianwdavishadley
authored andcommitted
Pass label to draw_key_text (#2458)
* Pass `label` to `draw_key_text` To override the default "a" in the label of a text legend: first check if `data$label` has anything in it; if not, use "a" as before. However, if the user sets a label within `guide_legend(override.aes = list(label = "foo"))`, then use that label or vector of labels as the first arg of `textGrob`. * Update NEWS.md Added description for issue #2458
1 parent a89bf86 commit 1d537ce

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101

102102
* The colorbar shows all colours of the scale (@has2k1, 2343).
103103

104+
* Guides generated by `geom_text()` (e.g. colour) now accept custom labels using
105+
`guide_legend(override.aes = list(label = "foo"))` (@brianwdavis, #2458).
106+
104107
### Margins
105108

106109
* Strips gain margins on all sides by default. This means that to fully justify

R/legend-draw.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ draw_key_smooth <- function(data, params, size) {
169169
#' @export
170170
#' @rdname draw_key
171171
draw_key_text <- function(data, params, size) {
172-
textGrob("a", 0.5, 0.5,
172+
if(is.null(data$label)) data$label <- "a"
173+
174+
textGrob(data$label, 0.5, 0.5,
173175
rot = data$angle,
174176
gp = gpar(
175177
col = alpha(data$colour, data$alpha),

0 commit comments

Comments
 (0)