I would like to modify the guide_colorbar
of a continuous aesthetic with character descriptions, e.g., 'low' and 'high', instead of actual numbers. This can be especially useful when using one legend or colorbar for multiple plots (heatmaps, e.g, geom_bin2d
).
Here an example.
Say given dummy data:
dd <- data.frame(xx=rnorm(100),yy=rnorm(100),zz=rep(1:10,10))
I can do the usual
ggplot(dd,aes(xx,yy,color=zz))+
geom_point()+
viridis::scale_color_viridis(option='A',direction=-1)
and hide colorbar annotations using
guides(color=guide_colorbar(ticks=F,label=F,title=element_blank()))
Another approach I tried is modifying the color aesthetics with
factor(zz,labels=c('low',2:9,'high'))
...
guides(color=guide_legend(override.aes=list(size=5,shape=15)))
and plotting as discrete. Also not really desired.
How do I add customized text to guide_colorbar
?
Or:
Is there a way to convert a discrete legend to a colorbar and keeping the character labels?