SlideShare a Scribd company logo
ggplot2:	An	extensible	platform	
for	publication-quality	graphics
Claus	O.	Wilke
The	University	of	Texas	at	Austin
@clauswilke clauswilke
Hadley	Wickham Thomas	Lin	Pederson
Edzer Pebesma Kamil Slowikowski
ggplot2: An Extensible Platform for Publication-quality Graphics
ggplot2: An Extensible Platform for Publication-quality Graphics
serialmentor.com/dataviz
What	do	we	need?
• Powerful	styling	options
• Broad	selection	of	plot	types
• Sophisticated	text	annotations
• Plot	composition
What	do	we	need?
• Powerful	styling	options
• Broad	selection	of	plot	types
• Sophisticated	text	annotations
• Plot	composition
ggplot2:	A	grammar	of	graphics	in	R
ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point()
ggplot2:	A	grammar	of	graphics	in	R
ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point() +
scale_color_viridis_d()
ggplot2:	A	grammar	of	graphics	in	R
ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point() +
scale_color_viridis_d() +
theme_bw()
What	do	we	need?
• Powerful	styling	options
• Broad	selection	of	plot	types
• Sophisticated	text	annotations
• Plot	composition
ggplot2-exts.org
Example	1:
Ridgeline	plots
Ridgeline	plots	are	a	variation	of	density	plots
ggplot(iris) +
aes(x = Sepal.Length, fill = Species) +
geom_density(alpha = 0.5)
Ridgeline	plots	are	a	variation	of	density	plots
library(ggridges)
ggplot(iris) +
aes(x = Sepal.Length, y = Species) +
geom_density_ridges(alpha = 0.5)
Ridgeline	plots	are	a	variation	of	density	plots
library(ggridges)
ggplot(iris) +
aes(x = Sepal.Length, y = Species) +
geom_density_ridges(alpha = 0.5)
Example	2:
Simple	features
sf:	Manipulating	and	plotting	simple	features
ggplot(TX_income, aes(fill = median_income)) +
geom_sf()
Edzer
Pebesma
TX_income[1:3,]
#> Simple feature collection with 3 features and 15 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -579099 ymin: -958812.5 xmax: -168152.2 ymax: -94284.87
#> epsg (SRID): NA
#> proj4string: +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96
+x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> STATEFP COUNTYFP COUNTYNS AFFGEOID GEOID NAME LSAD ALAND
#> 1 48 421 01383996 0500000US48421 48421 Sherman 06 2390651189
#> 2 48 493 01384032 0500000US48493 48493 Wilson 06 2081662847
#> 3 48 115 01383843 0500000US48115 48115 Dawson 06 2331781556
#> AWATER name median_income median_income_moe
#> 1 428754 Sherman County, Texas 51987 4386
#> 2 12111367 Wilson County, Texas 68100 3328
#> 3 4720730 Dawson County, Texas 41095 2591
#> population area popdens
#> 1 3066 2387929738 [m^2] 1.283957e-06 [1/m^2]
#> 2 45509 2086919506 [m^2] 2.180678e-05 [1/m^2]
#> 3 13542 2336898468 [m^2] 5.794860e-06 [1/m^2]
#> geometry
#> 1 MULTIPOLYGON (((-546533.1 -...
#> 2 MULTIPOLYGON (((-234487.5 -...
#> 3 MULTIPOLYGON (((-576468.3 -...
sf:	Manipulating	and	plotting	simple	features
ggplot(TX_income, aes(fill = median_income)) +
geom_sf() +
coord_sf(crs = 4326) # Cartesian longitude and latitude
Edzer
Pebesma
sf:	Manipulating	and	plotting	simple	features
ggplot(TX_income, aes(fill = median_income)) +
geom_sf() +
coord_sf(crs = 3338) # NAD83, Alaska Albers
Edzer
Pebesma
sf:	Manipulating	and	plotting	simple	features
# with formatting tweaks
ggplot(TX_income, aes(fill = median_income)) +
geom_sf(color = "black", size = 0.2) +
scale_fill_viridis_c(
name = "income",
labels = dollar
) +
theme_minimal()
Edzer
Pebesma
What	do	we	need?
• Powerful	styling	options
• Broad	selection	of	plot	types
• Sophisticated	text	annotations
• Plot	composition
ggplot2: An Extensible Platform for Publication-quality Graphics
ggrepel:	Smart	annotation	of	plot	elements
library(ggrepel)
mtcars$car <- rownames(mtcars) # add column of car names
mtcars %>% filter(disp < 200) %>%
ggplot(aes(disp, mpg, label = car)) +
geom_point() +
geom_text_repel()
Kamil Slowikowski
ggrepel:	Smart	annotation	of	plot	elements
library(ggrepel)
mtcars$car <- rownames(mtcars)
mtcars %>% filter(disp < 200) %>%
ggplot(aes(disp, mpg, label = car)) +
geom_point() +
geom_text_repel()
Kamil Slowikowski
ggrepel:	Smart	annotation	of	plot	elements
mtcars %>% filter(disp < 200) %>%
ggplot(aes(disp, mpg, label = car)) +
geom_point() +
geom_text_repel(xlim = c(180, 250), hjust = 0) +
xlim(70, 240)
Kamil Slowikowski
ggrepel:	Smart	annotation	of	plot	elements
mtcars %>% filter(disp < 200) %>%
ggplot(aes(disp, mpg, label = car)) +
geom_point() +
geom_text_repel(xlim = c(180, 250), hjust = 0) +
xlim(70, 240)
Kamil Slowikowski
ggrepel:	Smart	annotation	of	plot	elements
mtcars %>% filter(disp < 200) %>%
ggplot(aes(disp, mpg)) +
geom_point(aes(color = factor(am))) +
geom_text_repel(aes(label = ifelse(am == 0, car, ""))) +
scale_color_manual(
name = "transmission",
labels = c("manual", "automatic"),
values = c("red", "gray50")
)
Kamil Slowikowski
ggrepel:	Smart	annotation	of	plot	elements
mtcars %>% filter(disp < 200) %>%
ggplot(aes(disp, mpg)) +
geom_point(aes(color = factor(am))) +
geom_text_repel(aes(label = ifelse(am == 0, car, ""))) +
scale_color_manual(
name = "transmission",
labels = c("manual", "automatic"),
values = c("red", "gray50")
)
Kamil Slowikowski
What	do	we	need?
• Powerful	styling	options
• Broad	selection	of	plot	types
• Sophisticated	text	annotations
• Plot	composition
ggplot2: An Extensible Platform for Publication-quality Graphics
patchwork:	A	grammar	of	plot	composition	
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point()
p2 <- ggplot(iris, aes(Species, Sepal.Length)) +
geom_boxplot()
# add plots to place them side-by-side
p1 + p2
Thomas	Lin	
Pederson
Thomas	Lin	
Pederson
patchwork:	A	grammar	of	plot	composition	
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point()
p2 <- ggplot(iris, aes(Species, Sepal.Length)) +
geom_boxplot()
# add plots to place them side-by-side
p1 + p2
patchwork:	A	grammar	of	plot	composition	
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point()
p2 <- ggplot(iris, aes(Species, Sepal.Length)) +
geom_boxplot()
# divide plots to place them on top of each other
p1 / p2
Thomas	Lin	
Pederson
Thomas	Lin	
Pederson
patchwork:	A	grammar	of	plot	composition	
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point()
p2 <- ggplot(iris, aes(Species, Sepal.Length)) +
geom_boxplot()
# divide plots to place them on top of each other
p1 / p2
patchwork:	A	grammar	of	plot	composition	
p3 <- ggplot(iris, aes(Sepal.Length)) +
geom_density(fill = "gray60") +
facet_wrap(~Species)
# nested arrangements are possible
p3 / (p1 + p2)
Thomas	Lin	
Pederson
Thomas	Lin	
Pederson
patchwork:	A	grammar	of	plot	composition	
p3 <- ggplot(iris, aes(Sepal.Length)) +
geom_density(fill = "gray60") +
facet_wrap(~Species)
# nested arrangements are possible
p3 / (p1 + p2)
patchwork:	A	grammar	of	plot	composition	
p3 <- ggplot(iris, aes(Sepal.Length)) +
geom_density(fill = "gray60") +
facet_wrap(~Species)
# apply theme recursively to all plots
p3 / (p1 + p2) & theme_minimal()
Thomas	Lin	
Pederson
Thomas	Lin	
Pederson
patchwork:	A	grammar	of	plot	composition	
p3 <- ggplot(iris, aes(Sepal.Length)) +
geom_density(fill = "gray60") +
facet_wrap(~Species)
# apply theme recursively to all plots
p3 / (p1 + p2) & theme_minimal()
Read	the	source,	Luke
Acknowledgments
ggplot2	team
Hadley	Wickham
Winston	Chang
Lionel	Henry
Thomas	Lin	Pedersen
Kohske Takahashi
Hiroaki	Yutani
Kara	Woo
Specific	package	authors
Edzer Pebesma (sf)
Kamil Slowikowski (ggrepel)
Thomas	Lin	Pedersen	(patchwork)
The	broader	R	community
Mara	Averick
Yihui Xie
RStudio
many	others
Claus	O.	Wilke	receives	funding	from:	UT	Austin,	R	Consortium,	NIH,	NSF

More Related Content

PPTX
RBootcamp Day 4
PPTX
RBootcam Day 2
PPTX
R Bootcamp Day 3 Part 1 - Statistics in R
PDF
Ggplot2 cheatsheet-2.1
PDF
PDF
How big-is-your-graph
DOCX
Surface3d in R and rgl package.
DOCX
imager package in R and examples..
RBootcamp Day 4
RBootcam Day 2
R Bootcamp Day 3 Part 1 - Statistics in R
Ggplot2 cheatsheet-2.1
How big-is-your-graph
Surface3d in R and rgl package.
imager package in R and examples..

What's hot (20)

PDF
Data visualization with multiple groups using ggplot2
PDF
Geo Spatial Plot using R
DOCX
Basic Calculus in R.
DOCX
Advanced Data Visualization in R- Somes Examples.
PPTX
PDF
Day 2a examples
DOCX
Advanced Data Visualization Examples with R-Part II
PDF
Audio chord recognition using deep neural networks
DOCX
Data Visualization with R.ggplot2 and its extensions examples.
PDF
Polimorfismo cosa?
PPTX
statistical computation using R- an intro..
PDF
Big datacourse
PDF
Gremlin's Graph Traversal Machinery
PDF
Introduction to spatial data analysis in r
PDF
Beyond clicks dwell time for personalization
PDF
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
PPT
4.5 sec and csc worked 3rd
PDF
Scalar lenses-workshop
PDF
peRm R group. Review of packages for r for market data downloading and analysis
Data visualization with multiple groups using ggplot2
Geo Spatial Plot using R
Basic Calculus in R.
Advanced Data Visualization in R- Somes Examples.
Day 2a examples
Advanced Data Visualization Examples with R-Part II
Audio chord recognition using deep neural networks
Data Visualization with R.ggplot2 and its extensions examples.
Polimorfismo cosa?
statistical computation using R- an intro..
Big datacourse
Gremlin's Graph Traversal Machinery
Introduction to spatial data analysis in r
Beyond clicks dwell time for personalization
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
4.5 sec and csc worked 3rd
Scalar lenses-workshop
peRm R group. Review of packages for r for market data downloading and analysis
Ad

Similar to ggplot2: An Extensible Platform for Publication-quality Graphics (20)

PDF
data-visualization.pdf
PPTX
Tech talk ggplot2
PDF
Download full ebook of Datacamp Ggplot2 Cheatsheet Itebooks instant download pdf
PDF
r for data science 2. grammar of graphics (ggplot2) clean -ref
PPTX
Exploratory Analysis Part1 Coursera DataScience Specialisation
PDF
Data visualization using the grammar of graphics
ODP
The secrets of inverse brogramming
ODP
Introduction To PostGIS
DOCX
Data visualization with R and ggplot2.docx
DOCX
R-ggplot2 package Examples
PPTX
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
PPTX
Loom & Functional Graphs in Clojure @ LambdaConf 2015
PDF
Pycon2011
DOCX
CLUSTERGRAM
PDF
Python grass
PDF
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
PDF
Igraph
DOCX
Company_X_Data_Analyst_Challenge
PDF
M2M_250327_22434hjjik7_250411_183538.pdf
PPTX
R programming language
data-visualization.pdf
Tech talk ggplot2
Download full ebook of Datacamp Ggplot2 Cheatsheet Itebooks instant download pdf
r for data science 2. grammar of graphics (ggplot2) clean -ref
Exploratory Analysis Part1 Coursera DataScience Specialisation
Data visualization using the grammar of graphics
The secrets of inverse brogramming
Introduction To PostGIS
Data visualization with R and ggplot2.docx
R-ggplot2 package Examples
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Loom & Functional Graphs in Clojure @ LambdaConf 2015
Pycon2011
CLUSTERGRAM
Python grass
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Igraph
Company_X_Data_Analyst_Challenge
M2M_250327_22434hjjik7_250411_183538.pdf
R programming language
Ad

Recently uploaded (20)

PPTX
Computer network topology notes for revision
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PDF
Business Analytics and business intelligence.pdf
PDF
Lecture1 pattern recognition............
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PDF
Mega Projects Data Mega Projects Data
PPTX
1_Introduction to advance data techniques.pptx
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Computer network topology notes for revision
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
oil_refinery_comprehensive_20250804084928 (1).pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
Business Analytics and business intelligence.pdf
Lecture1 pattern recognition............
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Miokarditis (Inflamasi pada Otot Jantung)
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Introduction-to-Cloud-ComputingFinal.pptx
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
STUDY DESIGN details- Lt Col Maksud (21).pptx
Mega Projects Data Mega Projects Data
1_Introduction to advance data techniques.pptx
Data_Analytics_and_PowerBI_Presentation.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx

ggplot2: An Extensible Platform for Publication-quality Graphics