Working with multiple variables
A graphic can have more than two variables, not just what is plotted on the x and y axes. We can use colors, marker shapes, or sizes to differentiate data points and create a more complex visual. Look at these basic examples.
Scatterplots are the best fit for multiple variate plots, as the points can be changed to other shapes, sizes, or colors and produce a very rich visual. Knowing that the number of cylinders (cyl
) and horsepower (hp
) affect directly the fuel efficiency of a car (mpg
), a good exploration point is visualizing the effect of increasing cylinders and HP and observing how the fuel efficiency will respond. To perform the task, we plot a scatterplot that shows the relationship between the engine’s HP with the MPG presented by the car. Then, we add the cylinder information as a third variable to control the size of the bubbles, making them larger or smaller, thus bringing more information to this graphic:
# Scatterplot 3 variables...