R Tutorials
R Data Structures
R Graphics
R Statistics
R Examples
You learned in the Plot chapter that the plot()
function is used to arrange numbers against each other.
"Scatter structure" is a type of structure that is used to show the relationship between two dynamic numbers, and arranges one dot for each view.
Requires two vectors of the same length, one of the x (horizontal) axis and one of the y (vertical) axis:
Note in the example above should show the effect of 12 passing vehicles.
That may not be clear to anyone who sees the graph for the first time, so let's add a different title and label to better define the scatter plot:
Again, the observation in the example above is the result of 12 passing cars.
The x-axis shows how old the car is.
The y-axis shows the speed of the car as it passes.
Is there a relationship between the comments?
It looks like a new car driving at high speed but that may be a coincidence, as we only registered 12 cars.
In the example above, there seems to be a link between car speed and age, but what if we plan to see another day? Will the scattering plot tell us anything else?
To compare a building with another building, use the points()
function:
Draw two plots on the same figure
Note: In order to see the difference in contrast, you must assign different colors to the properties (using the col
parameter). Red represents 1 day values, while blue represents day 2. Note that we also add a cex
parameter to increase the size of the dots.
Viewpoint: By comparing these two episodes, I think it is safe to say that they both give us the same conclusion: if a car is new, it drives faster.