r - Generating a color legend with shifted labels using ggplot2 -



r - Generating a color legend with shifted labels using ggplot2 -

i plot maps using grads, , utilize color legend in plot this:

i same using ggplot2 in r. if using simply:

g <- g + scale_fill_brewer(palette="greens", na.value="na", name=legendtitle) #g saved plot simple options, prepared cut()

the output of course of study this:

so i'd able 2 things:

shift labels between colors, note indicating interval above (note: renaming labels not problem, shifting them is) last label should arrow-like, indicate entries above maximum (10 in example) indicated in darkest color (dark greenish in example).

edit: using help reply below, i've come this:

part 1. of question solved, if not perfect. i'd rid of white space between colors, idea? part 2... have no thought whatsoever.

my code snippet uses: theme(legend.position="bottom", legend.key.width = unit(1, "cm"), legend.key.height = unit(0.3, "cm")) + guides(fill=guide_legend(label.position = "bottom", label.hjust = 1.2))

here started.

the thought utilize cut() create cutting points, specify labels in way desire.

by putting legend @ bottom of plot, ggplot automatically puts legend labels "in between" 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")

r ggplot2

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -