O'Reilly logo

R Graph Essentials by David Alexander Lillis

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

Creating complex multiple axes

Now we will create a graph with two curves and three axes. First, let's read the following vectors of data:

x <- c(-25:25)

y <- 1.5*x + 2

z <- 0.3*(x**2) - 20

In the preceding code, we have a linear function and a quadratic function. As you will see, we will need some extra room for text on the right-hand margin. This is because we wish to add some explanatory text there. By default, graphs in R have margins that are as follows:

  • 5-lines wide on the bottom axis
  • 4-lines wide on the left-hand axis
  • 4-lines wide on the top axis
  • 2-lines wide on the right-hand axis

We want to create a right-hand margin 8.1-lines wide on the right axis using the mar argument, which controls margin widths:

par(mar=c(5, 4, 4, 8) + 0.1)

Note the ...

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