Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying R Graph Essentials
  • Table Of Contents Toc
R Graph Essentials

R Graph Essentials

4.5 (4)
close
close
R Graph Essentials

R Graph Essentials

4.5 (4)

Overview of this book

This book is targeted at R programmers who want to learn the graphing capabilities of R. This book will presume that you have working knowledge of R.
Table of Contents (6 chapters)
close
close
5
Index

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 syntax for changing the default margin width for any axis. You simply insert the desired line width value in the appropriate position within the mar argument. Now, we disable the default axes and plot as follows:

plot(x, y,type=&quot...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
R Graph Essentials
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon