x <- rnorm(50, mean=1, sd=2) plot(x) y <- seq(0,20, .1) z <- exp(-y/10)*cos(2*y) plot(y,z, type="l") x1 <- rnorm(50) plot(x1,x) plot(cbind(x1,x)) ts.plot(ldeaths) ts.plot(ldeaths,mdeaths,fdeaths,gpars=list(xlab="year",ylab="deaths",lty=1:3)) par(mfrow=c(2,2)) #a 2x2 plot plot(1:20,1:20,main="Straight Line") hist(rnorm(50),main="Histogram of Normal") qqnorm(rt(100,10),main="Samples from t(10)") plot(density(rnorm(50)),main="Normal Density") par(mfrow=c(1,1)) plot(x,main="Sample From Normal") plot(x,sub="Mean 1 and variance 4") plot(x, main="Sample from Normal", sub="Mean 1 and Variance 4") plot(x) title(main="Sample from Normal", sub="Mean 1 and Variance 4") plot(x, xlab="Index", ylab="Sample from Normal") plot(x, xlab="", ylab="") #no axis labels title(xlab="Index", ylab="Sample from Normal") par(mfrow=c(2,4)) plot(x, type="p") title(main="Points") plot(x, type="l") title(main="Lines") plot(x, type="b") title(main="Both Points and Lines") plot(x, type="c") title(main="Lines Part Alone") plot(x, type="o") title(main="Lines with points overstruck") plot(x, type="h") title(main="High Density") plot(x, type="s") title(main="Stairstep") plot(x, type="n") title(main="None") par(mfrow=c(1,1)) x <- runif(20) y <- 6*x+rnorm(20) x <- c(x,3) y <- c(y,4) plot(x,y) identify(x,y, n=1) #R waits until you click the mouse on the selected point plot(x,y) abline(lm(y~x), lty=2) plot(y^2, type="l", xlab="", ylab="Square of Y") lines(y, lty=2) lines(x, lty=4) plot(x, y, main="Adding Text") text(locator(1), "An outlier") #click the mouse to place the text plot(x, y, main="Adding Text") text(locator(1), "An outlier") #click the mouse to place the text ts.plot(ts(x),ts(y),gpars=list(lty=1:2)) #time series plot of both x and y leg.names <- c("Variable X","Variable Y") legend(locator(1), leg.names, lty=1:2) #click the mouse to place the legend z <- x+2*y+rnorm(21) pairs(cbind(x,y,z)) pet.length <- iris3[,3,] pet.width <- iris3[,4,] matplot(pet.length,pet.width) x<-seq(-2,2,length=10) y<-x^2 z<-x^3 matr<-cbind(x,y,z) matplot(x,matr)