Skip to Content
R: Data Analysis and Visualization
book

R: Data Analysis and Visualization

by Tony Fischetti, Brett Lantz, Jaynal Abedin, Hrishi V. Mittal, Bater Makhabel, Edina Berlinger, Ferenc Illés, Milán Badics, Ádám Banai, Gergely Daróczi, Barbara Dömötör, Gergely Gabler, Dániel Havran, Péter Juhász, István Margitai, Balázs Márkus, Péter Medvegyev, Julia Molnár, Balázs Árpád Szucs, Ágnes Tuza, Tamás Vadász, Kata Váradi, Ágnes Vidovics-Dancs
June 2016
Beginner to intermediate content levelBeginner to intermediate
1783 pages
71h 22m
English
Packt Publishing
Content preview from R: Data Analysis and Visualization

Displaying the data density on axes

In this recipe, we will learn how to show the density of data points on a scatter plot in the margin of the X or Y axes.

Getting ready

For this recipe, we don't need to load any additional libraries.

How to do it...

We will use the rug() function in the base graphics library. As a simple example to illustrate the use of this function, let's see the data density of a normal distribution:

x<-rnorm(1000)
plot(density(x))
rug(x)
How to do it...

How it works...

As can be seen from this example, the rug() function adds a set of lines just above the x-axis. A line or tick mark is placed wherever there is a point at that particular X location. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Exploratory Data Analysis with R

Hands-On Exploratory Data Analysis with R

Radhika Datar, Harish Garg

Publisher Resources

ISBN: 9781786463500Supplemental Content