Reputation: 89
I have used geom_rect to highlight 4 separate sections of my point plot graph, ggplot2 has used a default pink, green, blue and purple to shade in the rectangles, does anyone know of a way to change these default colours?
I didn't bother with a workable example but please let me know if you want one and I can post in comments
Upvotes: 2
Views: 3076
Reputation: 1373
Using scale_fill_manual
. An example:
library('ggplot2') #v 0.9.0
library('scales')
(unemp <- qplot(date, unemploy, data=economics, geom="line",
xlab = "", ylab = "No. unemployed (1000s)"))
presidential <- presidential[-(1:3), ]
yrng <- range(economics$unemploy)
xrng <- range(economics$date)
unemp + geom_vline(aes(xintercept = start), data = presidential)
unemp + geom_rect(aes(NULL, NULL, xmin = start, xmax = end, fill = party),
ymin = yrng[1], ymax = yrng[2],
data = presidential) +
scale_fill_manual(values = alpha(c("blue", "red"), 0.2))
More here: How can I have two different scale_fill_manual active in a ggplot command
Upvotes: 4