## Plots in R

R is awesome and making plots is very simple. I show a very simple Normal distribution plot here where a critical region P(D<d)=0.05 has been outlined. Here create a normal distribution with mean=1, sd =1.

png("myplot.png") x=seq(-3,5,length=200) y=dnorm(x,mean=1,sd=1) plot(x,y,type="l",lwd=2,col="red", xlab='X (D)->', ylab='Density->') x=seq(-3, -0.6448536,length=100) y=dnorm(x,mean=1,sd=1) polygon(c(-3,x, -0.6448536),c(0,y,0),col="gray") text(-1.5, 0.11, "P(Darrows(-1.5,0.09, x1=-1, 0.03) dev.off();

The critical region can be found using the source code below

qnorm(0.05,1 ,1); #cutoff point d = -0.6448536 pnorm(qnorm(0.05, 1,1), 1,1); #return 0.05. Finds P[D

The plot can be easily saved into an image format such as eps (which is used more commonly in latex) by replacing png(“myplot.png”) with postscript(“myplot.eps”).

Advertisements

## Leave a Reply