Microbiome figure in R
rstudio
microbiome
dataviz
Making figures for microbiome data in RStudio
This is an attempt to collate some useful commonly used figures for microbiome visualization.
Also applicable to data viz more generally.
At the moment I have this information spread across many different places.
🔗 Some links to this include
- Project website for publication on microbiome in wildlife & ticks
- Project website for publication on haemoprotozoa in wildlife & ticks
- 2022 BIO514 workshop
- 2021 BIO514 workshop
- 2021 BIO510 workshop
- Cryptick Lab NGS webpage
Packing circles
Using packcircles R package
Static image of packed circle plot
#install.packages("packcircles")
library(packcircles)
data("bacteria")
<- circleProgressiveLayout(bacteria)
packing <- circleLayoutVertices(packing)
dat.gg ggplot(data = dat.gg) +
geom_polygon(aes(x, y, group = id, fill = factor(id)),
colour = "black",
show.legend = FALSE) +
scale_fill_manual(values = bacteria$colour) +
scale_y_reverse() +
coord_equal()
Interactive figure for packed circle taxonomy plot
if (requireNamespace("ggiraph"))
<- ggplot(data = dat.gg) +
gg ::geom_polygon_interactive(
ggiraphaes(
x,
y,group = id,
fill = factor(id),
tooltip = bacteria$label[id],
data_id = id
),colour = "black",
show.legend = FALSE
+
) scale_fill_manual(values = bacteria$colour) +
scale_y_reverse() +
labs(title = "Hover over circle to display taxon name") +
coord_equal()
::ggiraph(ggobj = gg,
ggiraphwidth_svg = 5,
height_svg = 5)
Using circlepackeR R package
See package here jeromefroe/circlepackeR, to install devtools::install_github("jeromefroe/circlepackeR")
library(microbiome)
library(circlepackeR)
library(tidyverse)
library(hrbrthemes)
library(data.tree)
library(htmlwidgets)
<- aggregate_taxa(ps, 'Genus')
s <- psmelt(s)
melts <- melts
test # subset just the collowing column: Kingdom, Class, Order, Family, Genus
<- test[, c(12, 13, 15, 16, 17, 3)]
test <- subset(test, Abundance > 0)
test
$pathString <-
testpaste(test$Kingdom,
$Phylum,
test$Class,
test$Order,
test$Family,
test$Genus,
testsep = "/")
<- as.Node(test)
nodetest <- circlepackeR(nodetest, size = "Abundance")
all
# save html
saveWidget(all, file = "packedCircle_all.html")
# save pdf
# Make a webshot in pdf : high quality but can not choose printed zone
webshot("packedCircle_all.html" , "packedCircle_all.pdf")
# save png
# Make a webshot in png : Low quality - but you can choose shape
webshot(
"packedCircle_all.html" ,
"packedCircle_all.png",
delay = 0.2 ,
cliprect = c(440, 0, 1000, 10)
)