[R] different points and lines on the same plot

Petr Pikal petr.pikal at precheza.cz
Mon Jan 8 12:02:40 CET 2007


Hi

On 7 Jan 2007 at 9:32, Gabor Grothendieck wrote:

Date sent:      	Sun, 7 Jan 2007 09:32:54 -0500
From:           	"Gabor Grothendieck" <ggrothendieck at gmail.com>
To:             	"antoniababe at yahoo.se" <antoniababe at yahoo.se>
Copies to:      	r-help at stat.math.ethz.ch
Subject:        	Re: [R] different points and lines on the same plot

> Try this:
> 
> matplot(patient[,1], patient[,-1], type = "o")

Another option is to use plot and lines.

first initialise plotting region without any actual plotting

> plot(patient[,1], patient[,2], type="n", ylim=range(patient[,-1]))

then add lines in a cycle

> for(i in 1:4) lines(patient[,1], patient[,i+1], col=i, lwd=2, 
lty=i)

HTH
Petr



> 
> 
> On 1/7/07, antoniababe at yahoo.se <antoniababe at yahoo.se> wrote:
> > Dear all,
> >
> > I have following data called "paitent"
> >
> > day    patient1    patient4    patient5    patient6
> > 0   -0.27842688 -0.04080808 -0.41948398 -0.04508318
> > 56  -0.22275425 -0.01767067 -0.30977249 -0.03168185
> > 112 -0.08217659 -0.26209243 -0.29141451 -0.09876170
> > 252  0.08044537 -0.26701769  0.05727087 -0.09663701
> >
> > where each patient have response values at four time
> > points. I want to plot each patient's values over time
> > on the same plot where the value points are connected
> > by line. That is, the graph will have four lines for
> > the four patients. I tried the program below but
> > couldn't make it work correctly. I'm new beginner and
> > haven't yet learned how functions line and points work
> > together. Hope you can help me out.
> >
> > Thanks for your help,
> >
> > Antonia
> >
> > par(mfrow=c(1,1))
> >        plot(patient[,1],patient[,2], pch=1,
> > type="l",col=1,cex=1,lwd=2,
> >             xlab="Days", ylab="Patient
> > response",cex.main =1,font.main= 1,
> >             main=NULL)
> >
> >
> > points(patient[,1],patient[,3],col=2,pch=1,cex=1)
> > lines(patient[,1],patient[,3],col=2,lty=1,cex=1)
> >
> > points(patient[,1],patient[,4],col=3,pch=1,cex=1)
> > lines(patient[,1],patient[,4],col=2,lty=2,cex=1)
> >
> > points(patient[,1],patient[,5],col=4,pch=1,cex=1)
> > lines(patient[,1],patient[,5],col=2,lty=1,cex=1)
> >  points(patient[,1],patient[,6],col=5,pch=1,cex=1)
> >  lines(patient[,1],patient[,6],col=2,lty=1,cex=1)
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html and provide commented,
> > minimal, self-contained, reproducible code.
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list