ggplot2 Basics

To begin with, here is the exact same data, plotted both with plot() and ggplot(), respectively:

This is the built-in cars dataset, which contains only two variables, speed and dist. You can generate these plots yourself, as follows:

  • Plot 1:
plot(cars)
  • Plot 2:
library(ggplot2)ggplot(cars, aes(speed, dist)) + geom_point()

Voilà! A plot and a ggplot. Which is more aesthetically pleasing to you? Which would you rather publish on a report or your blog? The answer is probably the ggplot, if you're like most data scientists out ...

Get R Programming Fundamentals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.