Hi! Happy Merry Christmas in Advance!
I defined a function to alternate the labels in the legend.
However, whether using single or double intervals, the last label (as shown as 0.4 in the figure) always appears. When running the function independently, it produces puzzling results. The generated labels do not match those in the figure.
library(ggplot2)
v <- ggplot(faithfuld, aes(waiting, eruptions, z = density))
v +
geom_contour_filled(breaks = seq(0, 0.04, length.out = 8)) +
scale_fill_discrete(
palette = scales::pal_brewer(palette = "Blues"),
labels = function(brks) {
brks[seq_along(brks) %% 2 != 0] <- ""
return(brks)
}
) +
guides(fill = guide_colorsteps(show.limits = TRUE, position = 'bottom')) +
theme(legend.key.width = unit(40, 'pt'))
a <- function(brks) {
brks[seq_along(brks) %% 2 != 0] <- ""
return(brks)
}
a(seq(0, 0.04, length.out = 8))
#[1] "" "0.00571428571428571" ""
#[4] "0.0171428571428571" "" "0.0285714285714286"
#[7] "" "0.04"
Best wishes,
Hu