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 of the line graph:
> plot <- ggplot(mtcars, aes(wt, mpg))
  1. First, we draw the plot. At this point, the graph is not printed as we have not added layers to it. The ggplot needs at least one layer to display the graph:
> plot + geom_line()
  1. This plots the lines to produce the following line graph:

We can use various arguments to control how the line appears, such as linetype, for the type of line (solid, dashed, and so on), color of the line, and size of the line. We can also provide multiple arguments to this layer and this produces the following plot:

> plot ...

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