|
18 | 18 | #' @param barheight A numeric or a [grid::unit()] object specifying
|
19 | 19 | #' the height of the colorbar. Default value is `legend.key.height` or
|
20 | 20 | #' `legend.key.size` in [theme()] or theme.
|
| 21 | +#' @param frame.colour A string specifying the colour of the frame |
| 22 | +#' drawn around the bar. If `NULL` (the default), no frame is drawn. |
| 23 | +#' @param frame.linewidth A numeric specifying the width of the frame |
| 24 | +#' drawn around the bar. |
| 25 | +#' @param frame.linetype A numeric specifying the linetype of the frame |
| 26 | +#' drawn around the bar. |
21 | 27 | #' @param nbin A numeric specifying the number of bins for drawing colorbar. A
|
22 | 28 | #' smoother colorbar for a larger value.
|
23 | 29 | #' @param raster A logical. If `TRUE` then the colorbar is rendered as a
|
|
26 | 32 | #' raster image.
|
27 | 33 | #' @param ticks A logical specifying if tick marks on colorbar should be
|
28 | 34 | #' visible.
|
| 35 | +#' @param ticks.colour A string specifying the color of the tick marks. |
| 36 | +#' @param ticks.linewidth A numeric specifying the width of the tick marks. |
29 | 37 | #' @param draw.ulim A logical specifying if the upper limit tick marks should
|
30 | 38 | #' be visible.
|
31 | 39 | #' @param draw.llim A logical specifying if the lower limit tick marks should
|
@@ -109,8 +117,15 @@ guide_colourbar <- function(
|
109 | 117 | nbin = 20,
|
110 | 118 | raster = TRUE,
|
111 | 119 |
|
| 120 | + # frame |
| 121 | + frame.colour = NULL, |
| 122 | + frame.linewidth = 0.5, |
| 123 | + frame.linetype = 1, |
| 124 | + |
112 | 125 | # ticks
|
113 | 126 | ticks = TRUE,
|
| 127 | + ticks.colour = "white", |
| 128 | + ticks.linewidth = 0.5, |
114 | 129 | draw.ulim= TRUE,
|
115 | 130 | draw.llim = TRUE,
|
116 | 131 |
|
@@ -146,8 +161,15 @@ guide_colourbar <- function(
|
146 | 161 | nbin = nbin,
|
147 | 162 | raster = raster,
|
148 | 163 |
|
| 164 | + # frame |
| 165 | + frame.colour = frame.colour, |
| 166 | + frame.linewidth = frame.linewidth, |
| 167 | + frame.linetype = frame.linetype, |
| 168 | + |
149 | 169 | # ticks
|
150 | 170 | ticks = ticks,
|
| 171 | + ticks.colour = ticks.colour, |
| 172 | + ticks.linewidth = ticks.linewidth, |
151 | 173 | draw.ulim = draw.ulim,
|
152 | 174 | draw.llim = draw.llim,
|
153 | 175 |
|
@@ -271,6 +293,23 @@ guide_gengrob.colorbar <- function(guide, theme) {
|
271 | 293 | rectGrob(x = 0, y = by, vjust = 0, hjust = 0, width = barwidth, height = bh, default.units = "cm",
|
272 | 294 | gp = gpar(col = NA, fill = guide$bar$colour))
|
273 | 295 | })
|
| 296 | + } |
| 297 | + |
| 298 | + # make frame around color bar if requested (colour is not NULL) |
| 299 | + if (!is.null(guide$frame.colour)) { |
| 300 | + grob.bar <- grobTree( |
| 301 | + grob.bar, |
| 302 | + rectGrob( |
| 303 | + width = barwidth, |
| 304 | + height = barheight, |
| 305 | + default.units = "cm", |
| 306 | + gp = gpar( |
| 307 | + col = guide$frame.colour, |
| 308 | + lwd = guide$frame.linewidth, |
| 309 | + lty = guide$frame.linetype, |
| 310 | + fill = NA) |
| 311 | + ) |
| 312 | + ) |
274 | 313 | }
|
275 | 314 |
|
276 | 315 | # tick and label position
|
@@ -353,8 +392,14 @@ guide_gengrob.colorbar <- function(guide, theme) {
|
353 | 392 | x1 = c(rep(barwidth * (1/5), nbreak), rep(barwidth, nbreak))
|
354 | 393 | y1 = rep(tick_pos, 2)
|
355 | 394 | })
|
356 |
| - segmentsGrob(x0 = x0, y0 = y0, x1 = x1, y1 = y1, |
357 |
| - default.units = "cm", gp = gpar(col = "white", lwd = 0.5, lineend = "butt")) |
| 395 | + segmentsGrob( |
| 396 | + x0 = x0, y0 = y0, x1 = x1, y1 = y1, |
| 397 | + default.units = "cm", |
| 398 | + gp = gpar( |
| 399 | + col = guide$ticks.colour, |
| 400 | + lwd = guide$ticks.linewidth, |
| 401 | + lineend = "butt") |
| 402 | + ) |
358 | 403 | }
|
359 | 404 |
|
360 | 405 | # layout of bar and label
|
|
0 commit comments