Skip to content

Commit 67a10f8

Browse files
committed
enable guide_colorbar to work with nonstandard aesthetics
1 parent 9034d53 commit 67a10f8

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

R/guide-colorbar.r

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#' for `barwidth` and `barheight`.
4545
#' @param reverse logical. If `TRUE` the colorbar is reversed. By default,
4646
#' the highest value is on the top and the lowest value is on the bottom
47+
#' @param available_aes A vector of charater strings listing the aesthetics
48+
#' for which a colorbar can be drawn.
4749
#' @param ... ignored.
4850
#' @return A guide object
4951
#' @export
@@ -134,6 +136,7 @@ guide_colourbar <- function(
134136
default.unit = "line",
135137
reverse = FALSE,
136138
order = 0,
139+
available_aes = c("colour", "color", "fill"),
137140

138141
...) {
139142

@@ -180,7 +183,9 @@ guide_colourbar <- function(
180183
order = order,
181184

182185
# parameter
183-
available_aes = c("colour", "color", "fill"), ..., name = "colorbar"),
186+
available_aes = available_aes,
187+
...,
188+
name = "colorbar"),
184189
class = c("guide", "colorbar")
185190
)
186191
}
@@ -189,8 +194,9 @@ guide_colourbar <- function(
189194
guide_train.colorbar <- function(guide, scale) {
190195

191196
# do nothing if scale are inappropriate
192-
if (length(intersect(scale$aesthetics, c("color", "colour", "fill"))) == 0) {
193-
warning("colorbar guide needs colour or fill scales.")
197+
if (length(intersect(scale$aesthetics, guide$available_aes)) == 0) {
198+
warning("colorbar guide needs appropriate scales: ",
199+
paste(guide$available_aes, collapse = ", "))
194200
return(NULL)
195201
}
196202
if (scale$is_discrete()) {

man/guide_colourbar.Rd

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)