Читать книгу Probability with R - Jane M. Horgan - Страница 55
3.4 SCATTER PLOTS
ОглавлениеPlots of data are useful to investigate relationships between variables. To examine, for example, the relationship between the performance of students in Programming in Semesters 1 and 2, we could write
plot(prog1, prog2, xlab = "Programming Semester 1", ylab = "Programming Semester 2")
to obtain Fig. 3.14.
Figure 3.14 A Scatter Plot
When more than two variables are involved, R provides a facility for producing scatter plots of all possible pairs.
To do this, first create a data frame of all the variables that you want to compare.
courses <- results[2:5]
This creates a data frame containing the second to the fifth variables in , that is, and . Writing
pairs(courses)
or equivalently
pairs(results[2:5])
will generate Fig. 3.15, which, as you can see, gives scatter plots for all possible pairs.
Figure 3.15 Use of the Function