tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.48k stars 2.02k forks source link

Could colour bar guide ticks be more readable? #5852

Closed davidhodge931 closed 5 months ago

davidhodge931 commented 5 months ago

Currently, the ticks are hard to read when on light colours.

Also, the ticks on the side furthest from the labels are not required.

Possible solutions:

For either solution, it'd be cool if it was more minimalist with ticks only closest to the label

teunbrand commented 5 months ago

Some of these already have solutions. To just put ticks on one side of the colourbar, set the size to 0 for one of the ticks:

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
  geom_point()

p + theme(legend.ticks.length = rel(c(0.2, 0)))

To put ticks outside the bar, use negative tick lengths. If you make them too long, you might manually need to set the text margin for proper spacing. I'm overriding legend.ticks because white ticks can't be seen on white background.

p + theme(legend.ticks.length = rel(-0.2)),
          legend.ticks = element_line())

Created on 2024-04-22 with reprex v2.1.0

davidhodge931 commented 5 months ago

Aha, thanks @teunbrand !

Feel free to close, if you think defaults should stay as is

teunbrand commented 5 months ago

Changing these defaults will probably affect a lot of people's plots, so I'd rather refrain from that unless there is an objective improvement to be made. Stylistic sensibility varies from person to person, so let's leave this as is for now.