Home
Explore
Submit Search
Upload
Login
Signup
Advertisement
Check these out next
Tests in vitro de l'action inhibitrice de la croissance de P. falciparum par ...
Institut Pasteur de Madagascar
Open Access In Medicine
Martin Fenner
Into Clojure
Alf Kristian Støyle
Mobile Number Portability - The Process Factory
BSP Media Group
Ruby things
Julio Santos
mws_gen_aae_spe_ppttaylorrevisited.pdf
ssuser6ff4d5
ICSE-DAPSE 2013 talk
Olga Baysal
令和から本気出す
Takashi Kitano
1
of
33
Top clipped slide
Spruce up your ggplot2 visualizations with formatted text
Jan. 30, 2020
•
0 likes
5 likes
×
Be the first to like this
Show More
•
1,110 views
views
×
Total views
0
On Slideshare
0
From embeds
0
Number of embeds
0
Download Now
Download to read offline
Report
Technology
Talk given at rstudio::conf 2020, January 30, 2020.
Claus Wilke
Follow
Professor at The University of Texas at Austin
Advertisement
Advertisement
Advertisement
Recommended
Epidermal Nevi, Neoplasms and Cysts – Part 1 Epidermal Nevi, Neoplasms and ...
MedicineAndDermatology
7.1K views
•
100 slides
onychomycosis-tim-copy-190413065334 (1).pptx
Thal J Anggas
92 views
•
36 slides
Vesiculobullous disorders dermatology revision notes
TONY SCARIA
1.6K views
•
54 slides
S100 proteins & skin
M.YOUSRY Abdel-Mawla
2.8K views
•
42 slides
Cutaneous manifestations of internal malignancies.
prasad panuganti
2.8K views
•
59 slides
Logistical Regression.pptx
Ramakrishna Reddy Bijjam
135 views
•
24 slides
More Related Content
Similar to Spruce up your ggplot2 visualizations with formatted text
(20)
Tests in vitro de l'action inhibitrice de la croissance de P. falciparum par ...
Institut Pasteur de Madagascar
•
220 views
Open Access In Medicine
Martin Fenner
•
3.1K views
Into Clojure
Alf Kristian Støyle
•
854 views
Mobile Number Portability - The Process Factory
BSP Media Group
•
555 views
Ruby things
Julio Santos
•
230 views
mws_gen_aae_spe_ppttaylorrevisited.pdf
ssuser6ff4d5
•
3 views
ICSE-DAPSE 2013 talk
Olga Baysal
•
480 views
令和から本気出す
Takashi Kitano
•
1K views
Introducing Security Access Control Policies into Legacy Business Processes
Sébastien Mosser
•
534 views
R programming language
Alberto Minetti
•
879 views
01_introduction_lab.pdf
zehiwot hone
•
28 views
Assessing the impact of transposable element variation on mouse phenotypes an...
Thomas Keane
•
766 views
XML for bioinformatics
Pierre Lindenbaum
•
2K views
Benchmarking Perl (Chicago UniForum 2006)
brian d foy
•
2.4K views
An Exploration of the Formal Properties of PromQL
Brian Brazil
•
1.5K views
Data Science for Folks Without (or With!) a Ph.D.
Douglas Starnes
•
143 views
05 notion de pluviométrie
Altair mordor
•
12 views
Science Fiction Sensor Networks
Diego Pizzocaro
•
312 views
名古屋Ruby会議01 - Rubyでライフハッキング10連発♪
Shoya Tsukada
•
679 views
Connectix webserver
steveheer
•
82 views
Recently uploaded
(20)
Global Sustainable Masterbatch Market.pdf
Mohit BISResearch
•
0 views
Web3 vs metaverse.pdf
TarunTiwari94
•
0 views
Imaging During Pregnancy
VanshikaGarg76
•
0 views
Office 365 DLP-1.pptx
AnanyaShukla45
•
0 views
Airport kiosk
PanashiFZCO1
•
0 views
ImmortalGameDeck.pdf
Jun-You Liu
•
0 views
kamil.pdf
AzeemAslam11
•
2 views
Fab library construction protocol.pdf
AliceChang70
•
0 views
DNN Community Newsletter: An In-Person Review of Recent Open-Source Activity
Will Strohl
•
0 views
Web Performance Optimization
Livares Technologies Pvt Ltd
•
0 views
Q4 LESSON 2 MIL.pptx
DIOMEDISPOLLESCAS
•
0 views
MINOR PROJECT.pptx
YashikaSengar2
•
0 views
Advanced Testing
Postman
•
11 views
SYN: Ultra-Scale Software Evolution Comprehension [ICPC 2023]
Roberto Minelli
•
0 views
Dual Wall Insulated EBXL Cables for Electric Locomotive by Rohit Damodaran
Karupaswamy1
•
0 views
Ga4 Recommended ecommerce events.pdf
Codilar Technologies
•
0 views
SampleDecPkg.ppt
Courtney Doutherd
•
2 views
WordPress Coding Standards
Jonathan Bossenger
•
0 views
MS EXCEL LESSON.pptx
JoeyGarancho1
•
3 views
Artificial Intelligence by BlooHack.pptx
qshshw11
•
0 views
Advertisement
Spruce up your ggplot2 visualizations with formatted text
Spruce up your
ggplot2 visualizations with formatted text Claus O. Wilke The University of Texas at Austin https://wilkelab.org/ggtext @clauswilke clauswilke
A common problem: Mixing
italics and normal text in ggplot
https://stackoverflow.com/questions/39282293/r-ggplot2-using-italics-and-non-italics-in-the-same-category-label
bactname OTUname name
value Staphylococcaceae OTU 1 Staphylococcaceae (OTU 1) -0.5 Moraxella OTU 2 Moraxella (OTU 2) 0.5 Streptococcus OTU 3 Streptococcus (OTU 3) 2.0 Acinetobacter OTU 4 Acinetobacter (OTU 4) 3.0
bactname OTUname name
value Staphylococcaceae OTU 1 Staphylococcaceae (OTU 1) -0.5 Moraxella OTU 2 Moraxella (OTU 2) 0.5 Streptococcus OTU 3 Streptococcus (OTU 3) 2.0 Acinetobacter OTU 4 Acinetobacter (OTU 4) 3.0 data %>% ggplot(aes(name, value)) + geom_col() + coord_flip()
bactname OTUname name
value Staphylococcaceae OTU 1 Staphylococcaceae (OTU 1) -0.5 Moraxella OTU 2 Moraxella (OTU 2) 0.5 Streptococcus OTU 3 Streptococcus (OTU 3) 2.0 Acinetobacter OTU 4 Acinetobacter (OTU 4) 3.0 data %>% ggplot(aes(name, value)) + geom_col() + coord_flip()
https://stackoverflow.com/questions/39282293/r-ggplot2-using-italics-and-non-italics-in-the-same-category-label
How should we
specify formatted text?
data %>% ggplot(aes(name, value))
+ geom_col() + coord_flip() + ggtitle("species names are *in italics*")
data %>% ggplot(aes(name, value))
+ geom_col() + coord_flip() + ggtitle("species names are *in italics*") library(ggtext) # remotes::install_github('wilkelab/ggtext')
data %>% ggplot(aes(name, value))
+ geom_col() + coord_flip() + ggtitle("species names are *in italics*") + theme(plot.title = element_markdown()) library(ggtext) # remotes::install_github('wilkelab/ggtext')
data %>% mutate( name
= glue("*{bactname}* ({OTUname})") # library(glue) )
data %>% mutate( name
= glue("*{bactname}* ({OTUname})") # library(glue) ) bactname OTUname name value Staphylococcaceae OTU 1 *Staphylococcaceae* (OTU 1) -0.5 Moraxella OTU 2 *Moraxella* (OTU 2) 0.5 Streptococcus OTU 3 *Streptococcus* (OTU 3) 2.0 Acinetobacter OTU 4 *Acinetobacter* (OTU 4) 3.0
data %>% mutate( name
= glue("*{bactname}* ({OTUname})") ) %>% ggplot(aes(name, value)) + geom_col() + coord_flip() + theme(axis.text.y = element_markdown())
Your plots are
boring. Don’t you ever use color?
data %>% mutate( color
= c("#009E73", "#D55E00", "#0072B2", "#000000"), name = glue("<i style='color:{color}'>{bactname}</i> ({OTUname})") ) %>%
data %>% mutate( color
= c("#009E73", "#D55E00", "#0072B2", "#000000"), name = glue("<i style='color:{color}'>{bactname}</i> ({OTUname})") ) %>% ggplot(aes(name, value, fill = color)) + geom_col(alpha = 0.5) + coord_flip() + scale_fill_identity() + theme(axis.text.y = element_markdown())
What else can
you do?
https://stackoverflow.com/questions/14070953/photo- alignment-with-graph-in-r/30765590#30765590
labels <- c( Interphase
= "<img src='img/interphase.jpg' width='50' /><br>Interphase", Prophase = "<img src='img/prophase.jpg' width='50' /><br>Prophase", Metaphase = "<img src='img/metaphase.jpg' width='50' /><br>Metaphase", Anaphase = "<img src='img/anaphase.jpg' width='50' /><br>Anaphase", Telophase = "<img src='img/telophase.jpg' width='50' /><br>Telophase" ) https://stackoverflow.com/questions/14070953/photo- alignment-with-graph-in-r/30765590#30765590
https://stackoverflow.com/questions/14070953/photo- alignment-with-graph-in-r/30765590#30765590 labels <- c( Interphase
= "<img src='img/interphase.jpg' width='50' /><br>Interphase", ... ) ggplot(data, aes(phase, value, fill = cat)) + geom_col(position = "dodge") + scale_x_discrete(name = NULL, labels = labels) + theme(axis.text.x = element_markdown(lineheight = 1.2))
https://stackoverflow.com/questions/14070953/photo- alignment-with-graph-in-r/30765590#30765590 labels <- c( Interphase
= "<img src='img/interphase.jpg' width='50' /><br>Interphase", ... ) ggplot(data, aes(phase, value, fill = cat)) + geom_col(position = "dodge") + scale_x_discrete(name = NULL, labels = labels) + theme(axis.text.x = element_markdown(lineheight = 1.2))
Text boxes, backgrounds,
and word-wrapping https://wilkelab.org/ggtext
Does this only
work for theme elements?
ggplot(iris, aes(Sepal.Length, Sepal.Width))
+ geom_point() + geom_smooth(method = "lm") + facet_wrap(~Species)
iris_cor <- iris
%>% group_by(Species) %>% summarize(r_square = cor(Sepal.Length, Sepal.Width)^2) iris_cor #> # A tibble: 3 x 2 #> Species r_square #> <fct> <dbl> #> 1 setosa 0.551 #> 2 versicolor 0.277 #> 3 virginica 0.209
iris_cor <- iris
%>% group_by(Species) %>% summarize(r_square = cor(Sepal.Length, Sepal.Width)^2) %>% mutate( Sepal.Length = 8, Sepal.Width = 4.5, label = glue("*r*<sup>2</sup> = {round(r_square, 2)}") ) iris_cor #> # A tibble: 3 x 5 #> Species r_square Sepal.Length Sepal.Width label #> <fct> <dbl> <dbl> <dbl> <glue> #> 1 setosa 0.551 8 4.5 *r*<sup>2</sup> = 0.55 #> 2 versicolor 0.277 8 4.5 *r*<sup>2</sup> = 0.28 #> 3 virginica 0.209 8 4.5 *r*<sup>2</sup> = 0.21
ggplot(iris, aes(Sepal.Length, Sepal.Width))
+ geom_point() + geom_smooth(method = "lm") + geom_richtext( data = iris_cor, aes(label = label), hjust = 1, vjust = 1 ) + facet_wrap(~Species)
The package that
makes it all possible
text <- "Some
text **in bold.**" gp <- grid::gpar( fontfamily = "Comic Sans MS", fontsize = 20, col = "blue" ) g1 <- grid::textGrob(text, 0.1, 0.7, hjust = 0, gp = gp) grid::grid.draw(g1)
text <- "Some
text **in bold.**" gp <- grid::gpar( fontfamily = "Comic Sans MS", fontsize = 20, col = "blue" ) g1 <- grid::textGrob(text, 0.1, 0.7, hjust = 0, gp = gp) g2 <- gridtext::richtext_grob(text, 0.1, 0.4, hjust = 0, gp = gp) grid::grid.draw(g1) grid::grid.draw(g2)
https://wilkelab.org/ggtext https://wilkelab.org/gridtext @clauswilke clauswilke
Advertisement