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 facet plots


If you have a large dataset that includes a categorical variable, you can use the facets command to produce multiple graphs: one for each level of the categorical variable. In the following example, we will create a graph for each level of ETH (1, 2, and 3) using facets = ETH ~ . Note the tilde sign followed by the period. Enter this syntax:

qplot(HEIGHT, WEIGHT_1, data = T,  geom = "point",  main = "HEIGHT VS. WEIGHT BY ETHNICITY", xlab = "WEIGHT BEFORE TREATMENT (Kg)", ylab = "HEIGHT (cm)", facets = ETH ~ .)

Our facet plot is as follows:

Indeed, we have three scatterplots arranged vertically: one for each level of ETHNICITY. We can also create facet plots across the levels of two factor variables. In the following code, we will create a scatterplot of HEIGHT against WEIGHT_1 for each combination of SMOKE and EXERCISE in each facet, where the two levels of gender are represented by shape and color. Here is the required command:

qplot(HEIGHT, WEIGHT_1, data=T, shape=factor...
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