Skip to content

Trend graph

3 messages · C.H., Jim Lemon, Greg Snow

#
Dear R Gurus,

I have a problem related to plot.
For example, I have two variables, pre and post.

pre <- c(1,2,3,4,5)
post <- c(2,5,7,2,3)

How can I plot a line graph similar to this one?

http://www.pubmedcentral.nih.gov/articlerender.fcgi?artid=1847566&rendertype=figure&id=F1

Would you please provide me a keyword so that I can search. I don't
know what is the name of this type of graph.

Regards,
H
#
C.H. wrote:
Hi Chainsaw (both my wife and I like chainsaws),

I would use lines - I don't know of any specific function that will do this.

pp.mat<-cbind(pre,post)
plot(1:2,c(1,7),type="n",xaxt="n")
axis(1,at=1:2)
apply(pp.mat,1,lines)

Jim
2 days later
#
Try this:

pre <- c(1,2,3,4,5)
post <- c(2,5,7,2,3)

plot( 1:2, range(pre,post), type='n', xlab='', ylab='CRP (mg/dl)', xaxt='n')
segments(1,pre,2,post)
axis(1, at=1:2, labels=c('Pre','Post'))

### or one way to label the lines

par(mar=c(5,4,4,4)+0.1)

plot( 1:2, range(pre,post), type='n', xlab='', ylab='CRP (mg/dl)', xaxt='n')
segments(1,pre,2,post)
axis(1, at=1:2, labels=c('Pre','Post'))

tmp.y <- TeachingDemos::spread.labs(post, strheight('1'),
 min=min(post), max=max(post))

mtext( 1:5, side=4, at=tmp.y, line=2, las=1 )


hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111