O'Reilly logo

R Programming Fundamentals by Kaelen Medeiros

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required