September 2018
Beginner
206 pages
4h 27m
English
Scatterplot requires a bit more care than the other graphs we've covered to be truly meaningful and visually appealing. We'll return to our mtcars example of plotting mpg versus wt. If you recall the code used to build boxplots, you might be tempted to color the scatterplots using fill = cylfactor and code that looks like this:
ggplot(mtcars, aes(wt, mpg, fill = cylfactor)) + geom_point()
When we run this, we see that a legend has appeared that has the appropriate values of cylfactor, but the dots are all still black, so we've gained no new information. How do you think we fix this?
If you thought to yourself We need to use col = cylfactor in that aes() call, then you're absolutely right. The code should be:
ggplot(mtcars, aes(wt, ...
Read now
Unlock full access