example:
ggplot() +
geom_bar(data=Data,aes(x=factor(H),y=V),stat="identity") + facet_grid
(A~.,scales="free_y") +
geom_rect(aes(NULL, NULL, xmin = inicio, xmax = fim, fill = P), ymin =
0, ymax = max(Data$V),data = DT) +
scale_fill_manual(values =alpha(c("blue","red"), 0.2))
Error: Casting formula contains variables not found in molten data: A
> str(Data)
'data.frame': 48 obs. of 3 variables:
$ H: int 0 0 1 1 2 2 3 3 4 4 ...
$ A : int 2008 2009 2008 2009 2008 2009 2008 2009 2008 2009 ...
$ V : num 0 3 0 0 0 0 1 1 2 0 ...
>
> str(DT)
'data.frame': 3 obs. of 3 variables:
$ P: Factor w/ 2 levels "L","Pl": 2 1 2
$ inicio : num 0 8.5 18.5
$ fim : num 8.5 18.5 24.5
>
facet_grid needs to have data to facet on and since facetting is
global, the data should be in the ggplot() call.
ggplot(Data) +
geom_bar(data=Data,aes(x=factor(H),y=V),stat="identity") +
facet_grid(A~.,scales="free_y") +
geom_rect(aes(NULL, NULL, xmin = inicio, xmax = fim, fill = P), ymin =
0, ymax = max(Data$V),data = DT) +
scale_fill_manual(values =alpha(c("blue","red"), 0.2))
should work.
JiHO
---
http://maururu.net