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 Graphs Cookbook Second Edition
  • Table Of Contents Toc
R Graphs Cookbook Second Edition

R Graphs Cookbook Second Edition - Second Edition

By : Jaynal Abedin, Hrishi V. Mittal
4 (2)
close
close
R Graphs Cookbook Second Edition

R Graphs Cookbook Second Edition

4 (2)
By: Jaynal Abedin, Hrishi V. Mittal

Overview of this book

Targeted at those with an existing familiarity with R programming, this practical guide will appeal directly to programmers interested in learning effective data visualization techniques with R and a wide-range of its associated libraries.
Table of Contents (17 chapters)
close
close
16
Index

Adding error bars


In most scientific data visualizations, error bars are required to show the level of confidence in the data. However, there is no predefined function in the base R library to draw error bars. In this recipe, we will learn how to draw error bars in scatter plots.

Getting ready

All you need for the next recipe is to type it at the R prompt as we will use some base library functions to define a new error bar function. You can also save the recipe's code as a script so that you can use it again later on.

How to do it...

Let's draw vertical error bars with 5 percent errors on our cars' scatter plot using the arrows() function:

plot(mpg~disp,data=mtcars)

arrows(x0=mtcars$disp,
y0=mtcars$mpg*0.95,
x1=mtcars$disp,
y1=mtcars$mpg*1.05,
angle=90,
code=3,
length=0.04,
lwd=0.4)

To add horizontal error bars (also 5 percent in both directions) to the same graph, run the following code after creating the preceding graph:

arrows(x0=mtcars$disp*0.95,
y0=mtcars$mpg,
x1=mtcars$disp*1.05,
y1=mtcars...
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 Graphs Cookbook Second Edition
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