Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ggplot2 Essentials

You're reading from   ggplot2 Essentials Explore the full range of ggplot2 plotting capabilities to create meaningful and spectacular graphs

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781785283529
Length 234 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Donato Teutonico Donato Teutonico
Author Profile Icon Donato Teutonico
Donato Teutonico
Arrow right icon
View More author details
Toc

Creating a plot layer by layer with the ggplot function


We have already seen that qplot()is a simple function that can be used to generate plots quickly, but for more detailed control of the plot layers, the ggplot2 package also provides a more sophisticated function, ggplot(). Using this function, we first create a plot object in which we define the data and the aesthetic mapping we are interested in representing, and afterwards, we add elements such as geom and stat that produce the actual plot. Just remember that aesthetic mapping not only includes the colors and sizes of plotting elements, but also the x-y mapping to the axis. In the previous chapter, we showed an example of creating a scatterplot with the ToothGrowth dataset, where it described the effect of vitamin C on tooth growth in guinea pigs. We will now use the same dataset as an example and discuss how you can build the plot in Figure 2.14 of Chapter 2, Getting Started by adding one layer on top of the other.

First of all, we...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image