forked from microbiome/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemes.Rmd
executable file
·130 lines (104 loc) · 3.56 KB
/
Themes.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: "Themes"
author: "Leo Lahti, Sudarshan Shetty et al."
bibliography:
- bibliography.bib
output:
BiocStyle::html_document:
number_sections: no
toc: yes
toc_depth: 4
toc_float: true
self_contained: true
thumbnails: true
lightbox: true
gallery: true
use_bookdown: false
highlight: haddock
---
<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{microbiome tutorial - clustering}
%\usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
-->
## Cross-plot themes
Load example data:
```{r core-prevalence, message=FALSE, warning=FALSE}
# Load data
library(microbiome)
data(atlas1006)
# Rename the data
pseq <- subset_samples(atlas1006, DNA_extraction_method == "r")
```
```{r crossplot1, fig.width=6, fig.height=5, warning=FALSE, message=FALSE, fig.show="hold", out.width="300px"}
library(hrbrthemes)
library(gcookbook)
library(tidyverse)
# Themes from https://github.com/hrbrmstr/hrbrthemse
p <- ggplot(meta(pseq), aes(age, diversity)) +
geom_point() +
labs(x="Age (y)", y="Diversity (Shannon)",
title="HITChip Atlas",
subtitle="Age-diversity relation",
caption="Caption shown here 'g'")
print(p + theme_ipsum() + ggtitle("HITChip - theme_ipsum"))
print(p + theme_ipsum_rc() + ggtitle("HITChip - theme_ipsum_rc"))
```
## Color fill example
```{r crossplot2, fig.width=6, fig.height=5, warning=FALSE, message=FALSE, fig.show="hold", out.width="300px"}
# Theme from https://github.com/hrbrmstr/hrbrthemse
p <- ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) +
geom_area() +
scale_fill_ipsum() +
scale_x_continuous(expand=c(0,0)) +
scale_y_comma() +
labs(title="Age distribution of population in the U.S., 1900-2002",
subtitle="Example data from the R Graphics Cookbook",
caption="Source: R Graphics Cookbook") +
theme_ipsum_rc(grid="XY") +
theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) +
theme(legend.position="bottom")
print(p)
```
## Barplot example
```{r crossplot3, fig.width=6, fig.height=5, warning=FALSE, message=FALSE, fig.show="hold", out.width="300px", eval=FALSE}
update_geom_font_defaults(font_rc_light)
df <- count(mpg, class) %>%
mutate(n = n*2000) %>%
arrange(n) %>%
mutate(class=factor(class, levels=class))
p <- ggplot(df, aes(class, n)) +
geom_col() +
geom_text(aes(label=scales::comma(n)), hjust=0, nudge_y=2000) +
scale_y_comma(limits=c(0,150000)) +
coord_flip() +
labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 column chart example with commas",
subtitle="A plot that is only useful for demonstration purposes, esp since you'd never\nreally want direct labels and axis labels",
caption="Caption goes here") +
theme_ipsum_rc(grid="X")
print(p)
```
## Viridis scale
```{r core2, fig.width=9, fig.heigth=6, out.width="400px", warning=FALSE}
# Load data
library(microbiome)
data(peerj32)
# Rename the data
pseq <- peerj32$phyloseq
# Calculate compositional version of the data
# (relative abundances)
pseq.rel <- microbiome::transform(pseq, "compositional")
# With compositional (relative) abundances
det <- c(0, 0.1, 0.5, 2, 5, 20)/100
prevalences <- seq(.05, 1, .05)
p <- plot_core(pseq.rel, prevalences = prevalences, detections = det, plot.type = "lineplot") + xlab("Relative Abundance (%)")
# Same with the viridis color palette
# color-blind friendly and uniform
# options: viridis, magma, plasma, inferno
# https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html
# Also discrete=TRUE versions available
library(viridis)
print(p + scale_fill_viridis())
```