-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathREADME.rmd
366 lines (259 loc) · 13.9 KB
/
README.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
dev='svg',
fig.path = "figure/"
)
```
## gganatogram
```{r, include=FALSE}
if (requireNamespace("git2r")) {
repo = git2r::repository(".")
url = git2r::remote_url(repo, remote = "origin")
gh_user = basename(dirname(url))
} else {
gh_user = "jespermaag"
}
```
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/jespermaag/gganatogram?branch=master&svg=true)](https://ci.appveyor.com/project/`r gh_user`/gganatogram)
[![Travis build status](https://travis-ci.com/jespermaag/gganatogram.svg?branch=master)](https://travis-ci.com/`r gh_user`/gganatogram)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1434233.svg)](https://doi.org/10.5281/zenodo.1434233)
Create anatogram images for different organisms. <br/>
This package uses the tissue coordinates from the figure in Expression Atlas. [https://www.ebi.ac.uk/gxa/home](https://www.ebi.ac.uk/gxa/home) <br/>
[https://github.com/ebi-gene-expression-group/anatomogram](https://github.com/ebi-gene-expression-group/anatomogram) <br/>
```{r, eval=TRUE, echo=FALSE, AllSpeciesCellPlotValueTop, fig.width = 8, fig.height = 8, dpi = 300}
hgMale <- gganatogram(data=hgMale_key, fillOutline='#440154FF', organism='human', sex='male', fill="value") + theme_void() + scale_fill_viridis()
hgFemale <- gganatogram(data=hgFemale_key, fillOutline='#440154FF', organism='human', sex='female', fill="value") + theme_void() + scale_fill_viridis()
mmMale <- gganatogram(data=mmMale_key, fillOutline='#440154FF', organism='mouse', sex='male', fill="value") + theme_void() + scale_fill_viridis()
mmFemale <- gganatogram(data=mmFemale_key, outline = T, fillOutline='#440154FF', organism='mouse', sex='female', fill="value") +theme_void() + scale_fill_viridis()
grid.arrange(hgMale, hgFemale, mmMale, mmFemale, ncol=2)
```
```{r, eval=TRUE, echo=FALSE, CellPlotValueTop, fig.width = 8, fig.height = 4, dpi = 300}
p1 <- gganatogram(data=cell_key[['cell']], outline = T, fillOutline='steelblue', organism="cell", fill="colour") +theme_void() + coord_fixed()
p2 <- gganatogram(data=cell_key[['cell']], outline = T, fillOutline='lightgray', organism="cell", fill="value") +theme_void() + coord_fixed() + scale_fill_viridis()
grid.arrange(p1, p2, ncol=2)
```
## Citation
#### Maag JLV. gganatogram: An R package for modular visualisation of anatograms and tissues based on ggplot2 [version 1; referees: 1 approved]. F1000Research 2018, 7:1576 (doi: 10.12688/f1000research.16409.1)
https://f1000research.com/articles/7-1576/v1
```{r}
citation("gganatogram")
```
If you use the tissue plots from gganatogram please cite Expression Atlas as well. <br/>
[Petryszak et al. 2015](https://academic.oup.com/nar/article/44/D1/D746/2502589) <br/>
If you use the main cell figure, please cite The Protein Atlas. <br/>
[Thul PJ et al. 2017](http://science.sciencemag.org/content/356/6340/eaal3321) <br/>
More plot examples can be found at [https://jespermaag.github.io/blog/2018/gganatogram/](https://jespermaag.github.io/blog/2018/gganatogram/)
## Install
Install from github using devtools.
```{r,eval=FALSE}
## install from Github
devtools::install_github("jespermaag/gganatogram")
```
## shiny
I have now included a shiny app for gganatogram. <br/>
An online version can be found at shinapps.io. <br/>
[https://jespermaag.shinyapps.io/gganatogram/](https://jespermaag.shinyapps.io/gganatogram/) <br/>
Unfortunately, there is a limit of 25h per month of app activity, so if you know R/Rstudio, please run it locally. <br/>
To run it locally, use the following command.
```{r, eval=FALSE}
library(shiny)
runGitHub( "gganatogram", "jespermaag", subdir = "shiny")
```
## Usage
This package requires `ggplot2` and `ggpolypath` which loads when loading the package
```{r,eval=TRUE, message=FALSE}
library(gganatogram)
library(dplyr)
library(viridis)
library(gridExtra)
```
```{r, eval=TRUE, AllSpeciesPlot, fig.width = 10, dpi = 300}
hgMale <- gganatogram(data=hgMale_key, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") + theme_void()
hgFemale <- gganatogram(data=hgFemale_key, fillOutline='#a6bddb', organism='human', sex='female', fill="colour") + theme_void()
mmMale <- gganatogram(data=mmMale_key, fillOutline='#a6bddb', organism='mouse', sex='male', fill="colour") + theme_void()
mmFemale <- gganatogram(data=mmFemale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='female', fill="colour") +theme_void()
grid.arrange(hgMale, hgFemale, mmMale, mmFemale, ncol=4)
```
```{r, eval=TRUE, AllSpeciesPlotValue, fig.heigth = 6, dpi = 300}
hgMale <- gganatogram(data=hgMale_key, fillOutline='#440154FF', organism='human', sex='male', fill="value") + theme_void() + scale_fill_viridis()
hgFemale <- gganatogram(data=hgFemale_key, fillOutline='#440154FF', organism='human', sex='female', fill="value") + theme_void() + scale_fill_viridis()
mmMale <- gganatogram(data=mmMale_key, fillOutline='#440154FF', organism='mouse', sex='male', fill="value") + theme_void() + scale_fill_viridis()
mmFemale <- gganatogram(data=mmFemale_key, outline = T, fillOutline='#440154FF', organism='mouse', sex='female', fill="value") +theme_void() + scale_fill_viridis()
grid.arrange(hgMale, hgFemale, mmMale, mmFemale, ncol=2)
```
In order to use the function gganatogram, you need to have a data frame with
organ, colour, and value if you want to.
```{r, eval=TRUE}
organPlot <- data.frame(organ = c("heart", "leukocyte", "nerve", "brain", "liver", "stomach", "colon"),
type = c("circulation", "circulation", "nervous system", "nervous system", "digestion", "digestion", "digestion"),
colour = c("red", "red", "purple", "purple", "orange", "orange", "orange"),
value = c(10, 5, 1, 8, 2, 5, 5),
stringsAsFactors=F)
head(organPlot)
```
Using the function gganatogram with the filling the organs based on colour.
```{r, eval=TRUE, organPlot, fig.width = 3, dpi = 100}
gganatogram(data=organPlot, fillOutline='#a6bddb', organism='human', sex='male', fill="colour")
```
Of course, we can use the ggplot themes and functions to adjust the plots
```{r, eval=TRUE, organPlotvoid, fig.width = 3, dpi = 100}
gganatogram(data=organPlot, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
theme_void()
```
We can also plot all tissues available using hgMale_key
```{r, eval=TRUE, organPlotAll, fig.width = 3, dpi = 100}
hgMale_key$organ
gganatogram(data=hgMale_key, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +theme_void()
```
We can also skip plotting the outline of the graph
```{r, eval=TRUE, organPlotSubset, fig.width = 3, dpi = 100}
organPlot %>%
dplyr::filter(type %in% c('circulation', 'nervous system')) %>%
gganatogram(outline=F, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
theme_void()
```
We can fill the tissues based on the values given to each organ
```{r, eval=TRUE, organPlotValue, fig.width = 3, dpi = 100}
gganatogram(data=organPlot, fillOutline='#a6bddb', organism='human', sex='male', fill="value") +
theme_void() +
scale_fill_gradient(low = "white", high = "red")
```
We can also use facet_wrap to compare groups.
First create add two data frames together with different values and the conditions in the type column
```{r, eval=TRUE}
compareGroups <- rbind(data.frame(organ = c("heart", "leukocyte", "nerve", "brain", "liver", "stomach", "colon"),
colour = c("red", "red", "purple", "purple", "orange", "orange", "orange"),
value = c(10, 5, 1, 8, 2, 5, 5),
type = rep('Normal', 7),
stringsAsFactors=F),
data.frame(organ = c("heart", "leukocyte", "nerve", "brain", "liver", "stomach", "colon"),
colour = c("red", "red", "purple", "purple", "orange", "orange", "orange"),
value = c(5, 5, 10, 8, 2, 5, 5),
type = rep('Cancer', 7),
stringsAsFactors=F))
```
```{r, eval=TRUE, Condition, fig.width = 6, dpi = 100}
gganatogram(data=compareGroups, fillOutline='#a6bddb', organism='human', sex='male', fill="value") +
theme_void() +
facet_wrap(~type) +
scale_fill_gradient(low = "white", high = "red")
```
You can also split the tissues into types while retaining the outline
```{r, eval=TRUE, maleOrgans, fig.width = 10, fig.height = 8,dpi = 200}
gganatogram(data=hgMale_key, outline = T, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
facet_wrap(~type, ncol=4) +
theme_void()
```
## Added female option
All female tissues
```{r, eval=TRUE, female, fig.width = 3, dpi = 200}
hgFemale_key$organ
gganatogram(data=hgFemale_key, outline = T, fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +theme_void()
```
You can also split the tissues into types while retaining the outline
```{r, eval=TRUE, femaleOrgans, fig.width = 10, fig.height = 8, dpi = 200}
gganatogram(data=hgFemale_key, outline = T, fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +
facet_wrap(~type, ncol=4) +
theme_void()
```
To display the female reproductive system with outline.
```{r, eval=TRUE, femaleRep, fig.width = 6, dpi = 200}
hgFemale_key %>%
dplyr::filter(type=='reproductive') %>%
gganatogram( outline = T, fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +
theme_void() +
coord_cartesian(xlim = c(30, 75), ylim = c(-110, -80))
```
# Added mouse
## Male
```{r, eval=TRUE, maleMouse, figwidth = 3, dpi = 50}
mmMale_key$organ
gganatogram(data=mmMale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='male', fill="colour") +theme_void() +coord_fixed()
```
```{r, eval=TRUE, maleMouseOrgan, figwidth = 10, figheight = 8, dpi = 200}
gganatogram(data=mmMale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='male', fill="colour") +theme_void()+facet_wrap(~type, ncol=4)
```
## Female
```{r, eval=TRUE, femaleMouse, figwidth = 3, dpi = 50}
mmFemale_key$organ
gganatogram(data=mmFemale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='female', fill="colour") +theme_void() +coord_fixed()
```
```{r, eval=TRUE, femaleMouseOrgan, figwidth = 10, figheight = 8, dpi = 200}
gganatogram(data=mmFemale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='female', fill="colour") +theme_void()+facet_wrap(~type, ncol=4)
```
## Cellular structures
I have now included cellular substructures, using the cell.svg from the Protein Atlas.
If you use the main cell figure (hopefully more will be added), please cite [Thul PJ et al. 2017](http://science.sciencemag.org/content/356/6340/eaal3321) <br/>
The cellular data can be access using cell_key
```{r}
length(cell_key)
cell_key
```
To plot the whole cell with colours or values, use the following command.
If you want to specify a background colour, you either have to remove the cytosol or change the colour of cytosol to the desired colour.
```{r}
gganatogram(data=cell_key[['cell']], outline = T, fillOutline='steelblue', organism="cell", fill="colour") +theme_void() + coord_fixed()
gganatogram(data=cell_key[['cell']], outline = T, fillOutline='lightgray', organism="cell", fill="value") +theme_void() + coord_fixed() + scale_fill_viridis()
```
To see all the subsstructures individually, you can plot the data one at a time
```{r}
figureList <- list()
for (i in 1:nrow(cell_key[['cell']])) {
figureList[[i]] <- gganatogram(data=cell_key[['cell']][i,], outline = T, fillOutline='steelblue', organism="cell", fill="colour") +theme_void() +ggtitle(cell_key[['cell']][i,]$organ) + theme(plot.title = element_text(hjust=0.5, size=16)) + coord_fixed()
}
do.call(grid.arrange, c(figureList[1:4], ncol=2))
do.call(grid.arrange, c(figureList[5:8], ncol=2))
do.call(grid.arrange, c(figureList[9:12], ncol=2))
do.call(grid.arrange, c(figureList[13:16], ncol=2))
do.call(grid.arrange, c(figureList[17:20], ncol=2))
do.call(grid.arrange, c(figureList[21:24], ncol=2))
```
## Other organisms i.e. tier 2 organisms
Expression atlas contains other organisms than human and mice, however, these are not as well anotated. <br/>
All the expression atlas anatograms can be found here https://ebi-gene-expression-group.github.io/anatomogram/ <br/>
Unfortunately, I won't be able to add other organs to these since I'm neither an anatomist nor artist. <br/>
If anyone would like to add more organs, I would love for you to contribute. <br/>
<br/>
To create these plots, I have added two other objects other_key and other_list. <br/>
These are lists within lists, and to plot all the organs from an organisms use other_key[["organism"]] as data, and "organism" as organism. <br/>
Also, the organ names are so far a mix of UBERON and plant ids.
```{r}
length(other_key)
names(other_key)
```
To plot bos_taurus use the following command.
Unfortunately, I have not managed to add the correct names yet.
```{r, eval=TRUE, bosTaurus}
other_key[["bos_taurus"]]
gganatogram(data=other_key[["bos_taurus"]], outline = T, fillOutline='white', organism="bos_taurus", sex='female', fill="colour") +
theme_void() +
ggtitle("bos_taurus") +
theme(plot.title = element_text(hjust=0.5)) +
coord_fixed()
```
Here is a way to loop through all the other organisms and plot their organs.
```{r, eval=TRUE, othersFirst12, figwidth = 12, figheight = 16, dpi = 200}
library(gridExtra)
plotList <- list()
for (organism in names(other_key)) {
plotList[[organism]] <- gganatogram(data=other_key[[organism]], outline = T, fillOutline='white', organism=organism, sex='female', fill="colour") +
theme_void() +
ggtitle(organism) +
theme(plot.title = element_text(hjust=0.5, size=9)) +
coord_fixed()
}
do.call(grid.arrange, c(plotList[1:4], ncol=2))
do.call(grid.arrange, c(plotList[5:8], ncol=2))
do.call(grid.arrange, c(plotList[9:12], ncol=2))
do.call(grid.arrange, c(plotList[13:16], ncol=2))
do.call(grid.arrange, c(plotList[17:20], ncol=2))
do.call(grid.arrange, c(plotList[21:24], ncol=2))
```