# [R] Need help to draw a plot

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jun 23 15:38:26 CEST 2008

```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")
}

```