[R] funny plotting

Karla Meurk ksm32 at student.canterbury.ac.nz
Wed Jun 30 06:45:43 CEST 2004


Hi, I just wanted to plot a boxplot with a nice curve going through it, 
I thought this would be a simple task but for some reason I can't get 
the two graphs on the same page accurately. Enclosed is the code showing 
the two plots seperately and together.  I would have thought it should 
work if I could use boxplot() then plot() overlayed but it won't allow 
the command add=TRUE (which has worked for me in the past).

Thanks

Carla

P.S. please excuse the clumsy code!

#Section 2 Data Set particle

dial<-rbind(-1,
-1,
0,
0,
0,
0,
1,
1,
1)
counts<-rbind(2,
3,
6,
7,
8,
9,
10,
12,
15)
particle<-as.data.frame(cbind(dial,counts),row.names=NULL)
names(particle)<-c("dial","counts")
attach(particle)

pois.particle<-glm(counts~dial,family=poisson)
x<-seq(-2,2,length=20)
y<-predict(pois.particle,data.frame(dial=x),type="response")

#Overlaying plots
x11()
boxplot(counts~dial,main="Boxplot of counts for dial setting and poisson 
fit",ylim=c(0,25))
lines(x,y)

#The seperate plots
x11()
boxplot(counts~dial,ylim=c(0,25))
x11()
plot(x,y,ylim=c(0,25),type="l")




More information about the R-help mailing list