the function is now in the scales package. Use
library(scales)
library(ggplot2)
before your code
Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/
I moved the alpha transparency snippet to geom_rect() rather than
inside scale_fill_manual() and that works:
#library('ggplot2')
(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], alpha = 0.2,
data = presidential) +
scale_fill_manual(values = c("blue", "red"))
Another option is to load the scales package first since the alpha()
function has been moved there; unfortunately, the transparency
rendered is 1 rather than the desired 0.2; try
library('scales')
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))
I get the correct rectangles in red and blue, but they overwrite the
line plot in the region where the rectangles are defined with
transparency value 1. I don't know whether the problem is in
scale_fill_manual(), alpha() or their interaction, but it should be
looked at.
To me, the cleaner approach is to set alpha in geom_rect(); in
scale_fill_manual(), the code should work in principle, but I think
something is amiss at present. I'll raise an issue in the scales
package repo so that it will be in the pipeline for consideration.
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2