Thanks Harlan,
I got the short and long data frames. I guess I had understated/
misstated the question the first time. I wanted to superimpose 2
different distributions to two histograms (generated by facet_grid).
Is that possible?
I constructed this example:
value<-c(rpois(500,1.5))
group<-rep(c("A","B"),250)
data<-data.frame(value,group)
r<-range(value)
xfit<-seq(r[1]-0.5,r[2]-0.5, by=1)
xp<-xfit+0.5
pfit1<-dpois(xp,1)
pfit2<-dpois(xp,2)
yfit1<-pfit1*250
yfit2<-pfit2*250
GrpA<-data$value[data$group=="A"]
GrpB<-data$value[data$group=="B"]
breaks<-seq(r[1],r[2]+1, by=1)
A.cut=cut(GrpA,breaks,right=FALSE)
A=data.frame(table(A.cut))
B.cut=cut(GrpB,breaks,right=FALSE)
B=data.frame(table(B.cut))
data.short<-data.frame(xp,xfit,pfit1,yfit1,pfit2,yfit2,A$Freq,B$Freq)
g1<-ggplot(data,aes(value))
g2<-g1+geom_histogram(aes(y=..count..),binwidth=1,position="identity")
+facet_grid(.~group)
g2+geom_line(data=data.short,mapping=aes(xfit,yfit1),color="blue") +
geom_line(data=data.short,mapping=aes(xfit, yfit2), color="red")
Histogram for group A needs to be fitted with a yfit1. Group B needs
fitted with yfit2.
However, if I am using the same df data.short and using geom_line() to
plot the fits, I am getting both fits in both grids.
One way to avoid this would be to plot two histograms separately, but
can different curves be fitted to the two histograms generated by
facet_grid() and same short df at once?
Thanks,
KG
> > Please help!- Hide quoted text -
>
> - Show quoted text -