Hi! I am Mike Marin and in this video
we'll talk about producing "scatterplots" using R. "scatterplots" are appropriate
for examining the relationship between two numeric variables
we will be working with the Lung Capacity Data
that was introduced earlier in this series of videos. I've already gone ahead
and imported the data into R and attached it. we will graphically examine
the relationship between
Height and Age. we can produce a scatterplot
using the "plot" command. to access the Help menu
type "help" and the name of the command you would like help for
or simply throw a question mark (?) in front of the command name.
before constructing this plot let's calculate "Pearson's correlation"
to get an idea of the strength of the linear relationship between the two
variables
here we can see there's a fairly strong linear association
now let's go ahead and produce the scatterplot
using the "plot" command.
The variable that is entered first
will appear on the x-axis while the variable entered second
will appear on the y-axis. as before
we can add a title to this plot using the "main" argument
as well as label the
x-axis or y-axis using the "xlab"
or "ylab" arguments
I also like to rotate the values on the y-axis
by setting the "las" argument equal to 1. if desired
one can also change the x or y limits
using the "xlim" or "ylim" argument
here let's set the x-axis to run from 0
up to 25
while purely aesthetic, one may also change the size of the plotting characters
by using the "cex" argument. here we'll set it
equal to 0.5 to have the plotting characters that are half the
original size.
we may also change the plotting character we're using
using the "pch" argument
here we use plotting character 8; I've also removed the
"cex= 0.5" to have this character plotted at its
full-size
we may also change the color of the characters
using the "col" argument. here
we plot them in red. while we have not yet discussed
linear regression let's go ahead and add the linear
regression line that was fit to this plot. to do so
we can use the "abline" command and here we'll add the linear regression
predicting Height using Age
again we can change the color of this line
using the "col" argument. let's make the line blue.
finally we may wish to
add a nonparametric smoother to the plot to describe the relationship we're
observing
we can add a line using the "lines" command
and here we add a "smooth.spline"
to the plot for the relationship between
Age and Height
it is worth noting that a "spline" is just one of many
possible options for smoothers. if we would like
we can change the line type that we're plotting using the "lty"
argument. let's use line type number 2
and we can also change the width of the line using the "lwd" argument
let's set the equal to 5 to have a very thick line
to learn more about the plot command
explore the help menu. in later videos in this series
we'll talk more about refining these plots and making them even more
beautiful
thanks for watching this video and make sure to check out my other instructional videos