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

Labeling data points


In this recipe, we will learn how to label individual or multiple data points with text.

Getting ready

For this recipe, we don't need to load any additional libraries. We just need to type the recipe in the R prompt or run it as a script.

How to do it...

Let's say we want to highlight one data point in the cars' scatter plot that we used in the previous few recipes. We can label it using the text() command:

plot(mpg~disp, data=mtcars)
text(258,22,"Hornet")

How it works...

In the preceding example, we first plotted the graph and then used the text() function to overlay a label at a specific location. The text() function takes the x and y coordinates and the text of the label as arguments. We specified the location as (258,22) and the label text as Hornet. This function is especially useful when we want to label outliers.

There's more...

We can also use the text() function to label all the data points in a graph instead of just one or two. Let's look at another example where we...

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