Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
To make a scatter plot (Figure 2-1), use plot() and pass it a vector of x values
followed by a vector of y values:
plot(mtcars$wt,mtcars$mpg)
With the ggplot2 package, you can get a similar result using qplot()
(Figure 2-2):
library(ggplot2)qplot(mtcars$wt,mtcars$mpg)
If the two vectors are already in the same data frame, you can use the following syntax:
qplot(wt,mpg,data=mtcars)# This is equivalent to:ggplot(mtcars,aes(x=wt,y=mpg))+geom_point()
See Chapter 5 for more in-depth information about creating scatter plots.