|
72 | 72 | #' @param label.hjust The horizontal justification for the annotation. If it
|
73 | 73 | #' contains two elements the first will be used for the label and the second for
|
74 | 74 | #' the description.
|
75 |
| -#' @param label.fill The fill colour for the annotation box. |
| 75 | +#' @param label.fill The fill colour for the annotation box. Use `"inherit"` to |
| 76 | +#' use the fill from the enclosure or `"inherit_col"` to use the border colour |
| 77 | +#' of the enclosure. |
76 | 78 | #' @param label.colour The text colour for the annotation. If it contains
|
77 | 79 | #' two elements the first will be used for the label and the second for the
|
78 |
| -#' description. |
| 80 | +#' description. Use `"inherit"` to use the border colour of the enclosure or |
| 81 | +#' `"inherit_fill"` to use the fill colour from the enclosure. |
79 | 82 | #' @param label.buffer The size of the region around the mark where labels
|
80 | 83 | #' cannot be placed.
|
81 | 84 | #' @param con.colour The colour for the line connecting the annotation to the
|
82 |
| -#' mark. |
83 |
| -#' @param con.size The width of the connector. |
| 85 | +#' mark. Use `"inherit"` to use the border colour of the enclosure or |
| 86 | +#' `"inherit_fill"` to use the fill colour from the enclosure. |
| 87 | +#' @param con.size The width of the connector. Use `"inherit"` to use the border |
| 88 | +#' width of the enclosure. |
84 | 89 | #' @param con.type The type of the connector. Either `"elbow"`, `"straight"`, or
|
85 | 90 | #' `"none"`.
|
86 |
| -#' @param con.linetype The linetype of the connector. |
| 91 | +#' @param con.linetype The linetype of the connector. Use `"inherit"` to use the |
| 92 | +#' border linetype of the enclosure. |
87 | 93 | #' @param con.border The bordertype of the connector. Either `"one"` (to draw a
|
88 | 94 | #' line on the horizontal side closest to the mark), `"all"` (to draw a border
|
89 | 95 | #' on all sides), or `"none"` (not going to explain that one).
|
|
131 | 137 | #' geom_mark_circle(aes(fill = Species, label = Species),
|
132 | 138 | #' con.cap = 0) +
|
133 | 139 | #' geom_point()
|
| 140 | +#' |
| 141 | +#' # If you want to use the scaled colours for the labels or connectors you can |
| 142 | +#' # use the "inherit" keyword instead |
| 143 | +#' ggplot(iris, aes(Petal.Length, Petal.Width)) + |
| 144 | +#' geom_mark_circle(aes(fill = Species, label = Species), |
| 145 | +#' label.fill = "inherit") + |
| 146 | +#' geom_point() |
| 147 | +#' |
134 | 148 | NULL
|
135 | 149 |
|
136 | 150 | #' @rdname ggforce-extensions
|
@@ -187,29 +201,42 @@ GeomMarkCircle <- ggproto('GeomMarkCircle', GeomShape,
|
187 | 201 | }
|
188 | 202 | }
|
189 | 203 |
|
| 204 | + gp <- gpar( |
| 205 | + col = first_rows$colour, |
| 206 | + fill = alpha(first_rows$fill, first_rows$alpha), |
| 207 | + lwd = (first_rows$linewidth %||% first_rows$size) * .pt, |
| 208 | + lty = first_rows$linetype, |
| 209 | + fontsize = (first_rows$size %||% 4.217518) * .pt |
| 210 | + ) |
| 211 | + |
190 | 212 | circEncGrob(coords$x, coords$y,
|
191 | 213 | default.units = 'native',
|
192 | 214 | id = coords$group, expand = expand, radius = radius, n = n,
|
193 | 215 | label = label, ghosts = ghosts,
|
194 |
| - mark.gp = gpar( |
195 |
| - col = first_rows$colour, |
196 |
| - fill = alpha(first_rows$fill, first_rows$alpha), |
197 |
| - lwd = (first_rows$linewidth %||% first_rows$size) * .pt, |
198 |
| - lty = first_rows$linetype |
199 |
| - ), |
200 |
| - label.gp = gpar( |
201 |
| - col = label.colour, |
| 216 | + mark.gp = gp, |
| 217 | + label.gp = inherit_gp( |
| 218 | + col = label.colour[1], |
202 | 219 | fill = label.fill,
|
203 |
| - fontface = label.fontface, |
204 |
| - fontfamily = label.family, |
205 |
| - fontsize = label.fontsize, |
206 |
| - lineheight = label.lineheight |
| 220 | + fontface = label.fontface[1], |
| 221 | + fontfamily = label.family[1], |
| 222 | + fontsize = label.fontsize[1], |
| 223 | + lineheight = label.lineheight[1], |
| 224 | + gp = gp |
| 225 | + ), |
| 226 | + desc.gp = inherit_gp( |
| 227 | + col = rep_len(label.colour, 2)[2], |
| 228 | + fontface = rep_len(label.fontface, 2)[2], |
| 229 | + fontfamily = rep_len(label.family, 2)[2], |
| 230 | + fontsize = rep_len(label.fontsize, 2)[2], |
| 231 | + lineheight = rep_len(label.lineheight, 2)[2], |
| 232 | + gp = gp |
207 | 233 | ),
|
208 |
| - con.gp = gpar( |
| 234 | + con.gp = inherit_gp( |
209 | 235 | col = con.colour,
|
210 | 236 | fill = con.colour,
|
211 |
| - lwd = con.size * .pt, |
212 |
| - lty = con.linetype |
| 237 | + lwd = if (is.numeric(con.size)) con.size * .pt else con.size, |
| 238 | + lty = con.linetype, |
| 239 | + gp = gp |
213 | 240 | ),
|
214 | 241 | label.margin = label.margin,
|
215 | 242 | label.width = label.width,
|
@@ -297,7 +324,7 @@ geom_mark_circle <- function(mapping = NULL, data = NULL, stat = 'identity',
|
297 | 324 | circEncGrob <- function(x = c(0, 0.5, 1, 0.5), y = c(0.5, 1, 0.5, 0), id = NULL,
|
298 | 325 | id.lengths = NULL, expand = 0, radius = 0, n = 100,
|
299 | 326 | label = NULL, ghosts = NULL, default.units = 'npc',
|
300 |
| - name = NULL, mark.gp = gpar(), label.gp = gpar(), |
| 327 | + name = NULL, mark.gp = gpar(), label.gp = gpar(), desc.gp = gpar(), |
301 | 328 | con.gp = gpar(), label.margin = margin(),
|
302 | 329 | label.width = NULL, label.minwidth = unit(50, 'mm'),
|
303 | 330 | label.hjust = 0, label.buffer = unit(10, 'mm'),
|
@@ -335,10 +362,12 @@ circEncGrob <- function(x = c(0, 0.5, 1, 0.5), y = c(0.5, 1, 0.5, 0), id = NULL,
|
335 | 362 | label <- lapply(seq_len(nrow(label)), function(i) {
|
336 | 363 | if (is.na(label$label[i] %||% NA) && is.na(label$description[i] %||% NA)) return(zeroGrob())
|
337 | 364 | grob <- labelboxGrob(label$label[i], 0, 0, label$description[i],
|
338 |
| - gp = label.gp, pad = label.margin, width = label.width, |
| 365 | + gp = subset_gp(label.gp, i), desc.gp = subset_gp(desc.gp, i), |
| 366 | + pad = label.margin, width = label.width, |
339 | 367 | min.width = label.minwidth, hjust = label.hjust
|
340 | 368 | )
|
341 | 369 | if (con.border == 'all') {
|
| 370 | + con.gp <- subset_gp(con.gp, i) |
342 | 371 | grob$children[[1]]$gp$col <- con.gp$col
|
343 | 372 | grob$children[[1]]$gp$lwd <- con.gp$lwd
|
344 | 373 | grob$children[[1]]$gp$lty <- con.gp$lty
|
|
0 commit comments