Scale_fill_manual transparent colour

1,812 views
Skip to first unread message

Sergio René

unread,
Mar 12, 2012, 4:11:50 PM3/12/12
to ggplot2
Dear all:

I am having troubles for drawing a rectangle and then filling it with
a transparent colour. The problem is that the graphic generated has
the rectangle but the colour is solid. I am not sure what I am doing
wrong, below my code

Value<-rnorm(1000)
t<-(1:200)
Time<-c(t,t,t,t,t)
Model<-c(rep("A",200),rep("B",200), rep("C",200), rep("D",200),
rep("E",200))
Figure<-data.frame(Value, Time, Model)

### call the libraries
library("ggplot2")
library(reshape)

Plot<-qplot(x=Time, y=Value ,data=Figure, geom="line", colour="Model")
+
facet_wrap(~Model, ncol=2, scales="free")+
ylab("Error Term")+
scale_color_manual(values=c("blue"))+
scale_size_manual(values=c(10))+
geom_rect(aes(NULL, NULL,color=NULL, ymin=-1, ymax=1,fill=NA),
xmin=0, xmax=200,)+
scale_fill_manual(values = alpha(c("red"), 0.2))+
opts(axis.text.x=theme_text(size=16, colour="black"))+
opts(axis.text.y=theme_text(size=16, colour="black"))+
opts(axis.title.y=theme_text(size=16, colour="black", angle=90))+
opts(axis.title.x=theme_text(size=16, colour="black"))+
opts(strip.text.x=theme_text(size=16))+
opts(strip.text.y=theme_text(size=16,angle=270))+
opts(panel.grid.minor=theme_blank())+
opts(panel.grid.major=theme_blank())+
opts(panel.background=theme_rect(size=1))+
opts(strip.background=theme_rect(fill=NA, colour=NA))+
opts(legend.position="none")
Plot

Does anyone has an idea what I am doing wrong?

best,

Sergio René

baptiste auguie

unread,
Mar 12, 2012, 4:35:38 PM3/12/12
to Sergio René, ggplot2
Hi,

I think you want something like this,

geom_rect(aes(color=NULL, ymin=-1, ymax=1,xmin=0, xmax=200),
fill="red", alpha=0.5, data=data.frame(x=0,y=0))

without the dummy data, ggplot assumes that you're still using the
main data and overlays multiple rectangles (hence loses the
transparency). Not sure why inherit.aes doesn't appear to work here.

HTH,

baptiste

> --
> 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

Sergio René

unread,
Mar 12, 2012, 5:22:02 PM3/12/12
to ggplot2
Hi baptiste:

Thanks for the answer, I did as you suggested the only think is that I
have to set up the value of alpha to very low values, such as 0.002,
and then it shows some transparency, but seems to keep overdrawing
rectangles as the transparency looks weird,
thanks for the help,

best,

SR
Reply all
Reply to author
Forward
0 new messages