Scatter Plots

Sameer Mathur

A Simple Scatterplot using plot()

attach(mtcars)
plot(wt, mpg)

plot of chunk unnamed-chunk-1

A better Scatterplot of mpg vs wt

plot(wt, mpg, 
     col="blue",
     xlim=c(0, 8), ylim=c(0, 45), 
     main="Plot of MPG vs Car Weight",
     xlab="Weight ('000 lbs)", ylab="Miles Per Gallon")

A better Scatterplot of mpg versus wt

plot of chunk unnamed-chunk-3

Add Sample Means to the Scatterplot

plot(wt, mpg, 
     col="blue",
     xlim=c(0, 8), ylim=c(0, 40), 
     main="Plot of MPG vs Car Weight",
     xlab="Weight ('000 lbs)", ylab="Miles Per Gallon")
abline(h=mean(mpg), col="red", lty="dashed")
abline(v=mean(wt), col="blue", lty="dotted")

Add Sample Means to the Scatterplot

plot of chunk unnamed-chunk-5

A scatter plot without 'X' and 'Y' limit

Add Sample Mean lines to the Scatterplot

attach(mtcars)                                                     
plot(disp, mpg,
     col="black",
     main="Basic Scatterplot of MPG vs. Displacement",       
     xlab="Displacement", 
     ylab="Miles Per Gallon", pch=19)
abline(h=mean(mpg), col="red", lty="dotted")
abline(v=mean(disp), col="blue", lty="dotted")

A scatter plot without 'X' and 'Y' limit

Add Sample Mean lines to the Scatterplot

plot of chunk unnamed-chunk-7

Plotting Options