I have a data frame, called df, with 4 columns and 43010 lignes. The columns are X, Y, season, median. "X" and "Y" are lambert II coordinates of locations in France, "season" can have 5 values (Annual, Spring, Summer, Autumn and Winter), "median" is a number between -40 and 70 (a percentage in fact).
I want to plot a map of France for each season filled with the value "median". As I want discrete classes, I transformed the values of the "median" column like this :
vecP <- c(-40, -30, -20, -10, -5, 0, 5, 10, 20, 30, 70)
labP <- c("-40 ; -30", "-30 ; -20", "-20 ; -10", "-10 ; -5", "-5 ; 0", "0 ; 5", "5 ; 10", "10 ; 20", "20 ; 30", "30 ; 70")
df$sumBias <- cut(df$median, breaks=vecP, labels =labP)
So I have a fifth column with classes. Now, to plot :
colorsP <- brewer.pal(length(labP), "RdBu")
pdf(file=paste(graph_wd,"Bias.pdf",sep=""), width=4, height=9, paper = "special")
p <- ggplot(data = df, aes(x=X, y=Y))
p <- (p
+ theme_bw()
+ facet_wrap(~ season, ncol=1)
+ geom_tile(aes(fill= sumBias))
+ scale_fill_manual(name = "Bias (%)", values = setNames(colorsP, labP),breaks=rev(labP),labels=rev(labP),na.value="black")
+ geom_path(data = polfrance, colour = 'black',
aes(x = long, y = lat, group = group)))
p <- (p + scale_y_continuous(limits=c(1580000,2730000),
breaks=seq(1600000,2700000, 200000),
labels= seq(1600,2700,200), expand=c(0,0))
+ scale_x_continuous(limits=c(0,1250000),
breaks= seq(0,1250000, 400000),
labels= seq(0,1250, 400), expand=c(0,0))
+ theme(panel.grid.major = element_blank(), axis.text=element_blank(), axis.ticks=element_blank(), axis.title=element_blank())
+ coord_fixed(ratio=1))
print(p)
dev.off()
It gives me this figure:
My problem is the legend. Is it possible to have one number between two classes ? For example, "-30" between the two last red classes. Or something like that (the legend does not match, this is just to show what I want) :
Everything I tried always put one label next to one color class.
Thanks!
EDIT
With user20650 answer, I only modified, in the plot
+ scale_fill_manual(name = "Bias (%)",
values = setNames(colorsP, labP),
breaks=rev(labP),
labels=c("30", "20", "10", "5", "0", "-5", "-10", "-20", "-30", "-40"),
guide=guide_legend(label.vjust=-0.2),
na.value="black")
And it gives me this :
I just need to add one more label for "70" at the top of the scale, any idea?