Skip to content

Commit bad6f38

Browse files
Fix guide_bins() when the data has no size (#3593)
Fix #3582 * Subset key_size_mat only when it's not empty
1 parent 40e8b60 commit bad6f38

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

R/guide-bins.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ guide_gengrob.bins <- function(guide, theme) {
320320

321321
key_size_mat <- do.call("cbind",
322322
lapply(guide$geoms, function(g) g$data$size / 10)
323-
)[seq_len(n_keys), , drop = FALSE]
323+
)
324324

325+
# key_size_mat can be an empty matrix (e.g. the data doesn't contain size
326+
# column), so subset it only when it has any rows and columns.
325327
if (nrow(key_size_mat) == 0 || ncol(key_size_mat) == 0) {
326328
key_size_mat <- matrix(0, ncol = 1, nrow = n_keys)
329+
} else {
330+
key_size_mat <- key_size_mat[seq_len(n_keys), , drop = FALSE]
327331
}
328332
key_sizes <- apply(key_size_mat, 1, max)
329333

0 commit comments

Comments
 (0)