plotting many lines...

21 views
Skip to first unread message

Troels Ring

unread,
Apr 11, 2015, 11:37:38 AM4/11/15
to ggp...@googlegroups.com
Dear friends - terribly sorry for such an ugly question - I have a lot of lines from a linear model to plot and has done some of it but then cannot get further. 

summary(z1 <- lme(FITPH ~ MEASPH, random = ~1|PTID,RES)) # this is the model from nlme

F0 <- fitted(z1,level=0)   # this is the population mean
F1 <- fitted(z1,level=1)   # this is  for each of 76 individuals
I <- order(RES$MEASPH)
MPH <- sort(RES$MEASPH)
library(ggplot2)
library(scales)
apH<-seq(min(MPH),max(MPH),length=1000) #this is to make X=Y line
ident <- data.frame(MPH=apH,fpH=apH)
FH0 <- data.frame(pH=MPH,fpH = F0[I])

pp <- ggplot(FH0,aes(x=MPH,y= fpH))+geom_line(linetype=1,size=3,colour="blue")+
ylab("Fitted pH")+xlab("Measured pH")+xlim(c(6.9,7.7)) +ylim(c(6.9,7.7))
ppp <- pp + theme_bw()+ geom_line(data=ident ,size=3,col="red") # this all works fine and makes an overall line and X=Y

#But  then - to find individual lines in ordinary plot I just do this - but I cannot graps how to do in ggplot2 - really embarrassed
for (i in 1:length(outs)) {
x1 <- RES$MEASPH[RES$PTID==i]
y1 <- F1[RES$PTID==i]
K  <- order(x1)
lines(sort(x1),y1[K],lwd=0.1)}
Reply all
Reply to author
Forward
0 new messages