The results and ramblings of research

phewww!

Plots in R

leave a comment »

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”).

Cutoff Region where P(D<d)=0.05

Advertisements

Written by anujjaiswal

January 13, 2012 at 6:40 pm

Posted in R

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: