Here is something to get you started.
The idea is that you use cut()
to create the cut points, but specify the labels in the way you desire.
By putting the legend at the bottom of the plot, ggplot
automatically puts the legend labels "in between" the values.
library(ggplot2)
dat <- data.frame(x=0:100, y=runif(101, 0, 10), z=seq(0, 12, len=101))
dat$col <- cut(
dat$z,
breaks=c(0, 2, 4, 6, 8, 10, Inf),
labels=c(2, 4, 6, 8, 10, "-->")
)
ggplot(dat, aes(x, y, col=col)) +
geom_point(size=10) +
scale_colour_brewer("", palette="Greens") +
theme(legend.position="bottom")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…