O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

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

How it works...

Let's start from the top:

  1. We will first discuss some variations:
> plot <- ggplot(auto, aes(weight, mpg))
  1. First, we draw the plot. At this point, the graph is not printed as we have not added layers to it. The plot object need at least one layer to display the graph:
> plot + geom_point()

This plots the points to produce the following scatter plot:

  1. We can use various arguments to control how the points appear, for example, alpha, for the intensity of the dots, the color of the dots, and the size and shape of the dots. We can also use the aes argument to add aesthetics to this layer which produces the plot as follows:

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