Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove ticks / tiny white line from colorbar ggplot2

Tags:

r

legend

ggplot2

how to remove that white line from a ggplot2 colourbar?

ggplot(faithfuld, aes(waiting, eruptions)) +
  geom_raster(aes(fill = density)) +
  scale_fill_gradientn(colours = terrain.colors(10))+
theme(legend.key.height=unit(2,"line"))

generates this plot

enter image description here

But if you zoom in the legend, you will see tiny annoying white lines:

enter image description here

How can I remove them? Thanks

like image 260
Sergio Avatar asked Jun 19 '26 00:06

Sergio


1 Answers

You can set the ticks.colour= within guide_colorbar() by referencing via guides()... here ya go:

# where "plot" = your plot code...
plot + guides(fill=guide_colorbar(ticks.colour = "black"))

enter image description here

And to remove them, set the color to NA:

plot + guides(fill=guide_colorbar(ticks.colour = NA))

enter image description here

like image 95
chemdork123 Avatar answered Jun 21 '26 12:06

chemdork123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!