 InfluentialPoints.com
Biology, images, analysis, design...
 Use/Abuse Principles How To Related
"It has long been an axiom of mine that the little things are infinitely the most important" (Sherlock Holmes)

## Simple scatterplots and 'fitted' lines using R ### Scatterplots

R can produce a simple scatterplot, for variable y on x using these instructions:

Giving:   ### The simplest way to fit a straight line

The simplest way to get R to add a fitted line to a scatterplot is to use the following instructions - which perform what is known as a 'linear regression'. We consider why they work in Unit 12. Note, this assumes x and y contain the same number of values, and none are missing (=NA).

Giving:   If you feel this line is not a very good 'fit' to these data, it is because their spread is very uneven. One way to solve this is to rescale the values in variables x and y.

### A more complicated way to add a 'fitted line'

To rescale the data and fit a line using R's 'linear modelling' function, we could use the following instructions: Note, these instructions are more complicated than those above because they also use distinctive variable names - and provide headings for the graph.

Giving:    ### Another way to add a 'fitted line'

The following instructions use the calculator formula to fit a line to the rescaled data:

Giving:    