Skip to content

Commit 6872bf6

Browse files
authored
move last row back down after reversing (#4442)
1 parent b178d22 commit 6872bf6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 (development version)
22

3+
* Fix a bug in `guide_bins()` where keys would disappear if the guide was
4+
reversed (@thomasp85, #4210)
5+
36
* Fix a bug in legend justification where justification was lost of the legend
47
dimensions exceeded the available size (@thomasp85, #3635)
58

R/guide-bins.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ guide_train.bins <- function(guide, scale, aesthetic = NULL) {
144144

145145
if (is.numeric(breaks)) {
146146
limits <- scale$get_limits()
147+
breaks <- breaks[!breaks %in% limits]
147148
all_breaks <- c(limits[1], breaks, limits[2])
148149
bin_at <- all_breaks[-1] - diff(all_breaks) / 2
149150
} else {
@@ -163,7 +164,12 @@ guide_train.bins <- function(guide, scale, aesthetic = NULL) {
163164
key$.label <- scale$get_labels(all_breaks)
164165
guide$show.limits <- guide$show.limits %||% scale$show_limits %||% FALSE
165166

166-
if (guide$reverse) key <- key[nrow(key):1, ]
167+
if (guide$reverse) {
168+
key <- key[rev(seq_len(nrow(key))), ]
169+
# Move last row back to last
170+
aesthetics <- setdiff(names(key), ".label")
171+
key[, aesthetics] <- key[c(seq_len(nrow(key))[-1], 1), aesthetics]
172+
}
167173

168174
guide$key <- key
169175
guide$hash <- with(

0 commit comments

Comments
 (0)