Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use geom_point(), and
map one variable to x
and one to y.
In the heightweight data
set, there are a number of columns, but we’ll only use two in this
example (Figure 5-1):
library(gcookbook)# For the data set# List the two columns we'll useheightweight[,c("ageYear","heightIn")]ageYear heightIn11.9256.312.9262.312.7563.3...13.9262.012.5859.3
ggplot(heightweight,aes(x=ageYear,y=heightIn))+geom_point()
To use different shapes in a scatter plot, set shape. A common alternative to the default
solid circles (shape #16) is hollow ones (#21), as seen in Figure 5-2 (left):