# Re: [R] Need help to draw a plot

From: Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk>
Date: Mon, 23 Jun 2008 14:38:26 +0100

Ron Michael wrote:
> can i have some instruction on how to draw this type of plot in R :
>

The black curve and it's grey friends are probably easily done with plot or matplot, but you need to make sure the X-axis extends far enough to the right to get the red curve in.

The vertical and horizontal lines you can do with abline(v=1.0)

The red curve looks like a normal distribution turned sideways. You could do this with lines() as well, but switching the X and Y coords from what you'd usually do. You'll need par()\$usr to get the vertical range to compute the normal. Here's a fairly close facsimile except I couldn't be bothered to make the grey lines look exactly like your plot!

makeplot <- function(){

x=seq(0,1,len=50)

y=3*exp(-x)
yu=y/1.1+x
yl=y-(yu-y)

matplot(x,cbind(y,yu,yl),

```           col=c("black","grey","grey"),
lty=c(1,1,1),
,xlim=c(0,1.4),type='l',ylim=c(0,3),
xlab="t",ylab="Si")

```

mean=y[length(y)]
sd=0.2
abline(v=x[length(x)])
abline(h=1.0,lty=2)
xup=seq(par()\$usr,par()\$usr,len=50)    yup=dnorm(xup,mean,sd)/8
lines(1+yup,xup,col="red")
}

R-help_at_r-project.org 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. Received on Mon 23 Jun 2008 - 13:47:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 14:30:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.