Hey all,
I would like to reverse the legend of a continuous variable, so that small numbers are on top of the large numbers. Here is an example of the legend I would like to reverse:
df <- data.frame(x=1:20, y=runif(20), depth=runif(20, min=1, max=10))
pl <- ggplot(df, aes(x,y,colour=depth))
pl + geom_point() +
scale_colour_gradient(low="#5EB7F8", high="#1A334B")
I can create the reverse legend with "-depth" (and reverse high/low values), so it looks like how I want it to look like, but the negative numbers in the label are not really correct:
pl <- ggplot(df, aes(x,y,colour=-depth))
pl + geom_point() +
scale_colour_gradient(high="#5EB7F8", low="#1A334B")
I experimented with "guide_legend", which orders the labels as I want them, but it seems to change depth into a discrete factor; I would however like to keep the continuous scale:
pl <- ggplot(df, aes(x,y,colour=depth))
pl + geom_point() +
scale_colour_gradient(guide=guide_legend(reverse = FALSE), low="#5EB7F8", high="#1A334B")
I would be grateful for any help and suggestions!
Thanks,
Silke