1

I have a plot with a discrete colorscheme (109 different levels) and a colorstep legend. The legend then shows all ticks for each color. How can I only show a few of the labels and ticks in the legend rather than all? Plot 1 shows the legend when the labels are still there

Plot with labels

Plot 2 shows the legend without the labels. I want to show only certain labels in the legend, to make it actually understandable (10 different values rather than 100). How do I do that? My code is below, I am clearly doing something wrong, I just do not know what it is.

Plot without labels


tt <- ggplot() +
  # first layer: all countries, no fill, no white outlines
  geom_polygon(data = maps2, 
               aes(x = long, y = lat, group = group), fill="grey", show.legend = F, size = 0.1) +
  # second layer: only countries with a fill
  geom_polygon(data = test,
            aes(x = long, y = lat, group = group, fill = as.factor(tally)), show.legend = T)+  
  scale_fill_viridis_d(option="D", na.value = NA)+
  facet_grid(~IO)+
  theme( strip.text.x = element_blank())

tt + guides(fill=guide_colorsteps(label = F, title=element_blank())
H.Stevens
  • 391
  • 3
  • 16
  • Why? A continuous fill surely makes much more sense? – Allan Cameron Nov 12 '21 at 23:30
  • `scale_fill_continuous(breaks = c(1, 26, 51,76, 109,)) ` – Bloxx Nov 12 '21 at 23:32
  • Where you use `fill = as.factor(tally)`, it might make more sense to use `tally` alone. Perhaps you decided on `as.factor` because there's a high skew to your data and you want to capture a range of values along multiple orders of magnitude? In that case, you could use a transformation with a continuous color scale, like here: https://stackoverflow.com/a/8141847/6851825 – Jon Spring Nov 13 '21 at 00:03
  • Theoretically it makes more sense to use a continuous scale. However, for some reason I cannot distingish the colors then. The color distribution shifts somehow and the figure is almost only dark blue. I do not know how to shift the entire scale up either. There are 109 factor levels in tally, so displaying a discrete scale is also useless. – H.Stevens Nov 14 '21 at 14:04
  • The suggested solution from @JonSpring solved it! Thank you! – H.Stevens Nov 14 '21 at 14:24

0 Answers0