#Creating a basic scatter plot attach(cars) plot(speed,dist) #Adding a regression line to a scatter plot abline(lm(dist~speed)) #Making a scatter plot look good attach(cars) plot(speed,dist,main="Stopping Distance",xlab="Speed",ylab="Distance",pch=21,bg="red",col="red") #Adding points to a scatter plot read.table("cars2.txt",header=TRUE) cars2=read.table("cars2.txt",header=TRUE) attach(cars2) points(Speed,Distance,col="blue", pch=21,bg="blue") #Rescaling/Adding two data sets to a scatter plot attach(cars) cars2=read.table("cars2.txt",header=TRUE) attach(cars2) plot(c(speed,Speed),c(dist,Distance),xlab="Speed",ylab="Distance",main="Stopping Distances",type="n") points(speed,dist,col="red",pch=21,bg="red") points(Speed,Distance,col="blue",pch=21,bg="blue") #Adding a Legend and regression lines to each data set legend(locator(1),c("Car 1","Car 2"),pch=c(21,21),pt.bg=c("red","blue"),col=c("red","blue")) abline(lm(Distance~Speed)) abline(lm(dist~speed)) #Loess Regression attach(cars) plot(speed,dist,main="Stopping Distance", xlab="Speed", ylab="Distance", pch=21, bg=2, col=2) lines(lowess(cars, f=.3),col =1) lines(lowess(cars, f=.5),col =4) lines(lowess(cars, f=.1),col =7)