forked from zhaoxiaohe/plotTree-ggtree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
62 lines (41 loc) · 1.8 KB
/
README.Rmd
File metadata and controls
62 lines (41 loc) · 1.8 KB
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
# ggtree version of plotTree
[plotTree](https://github.com/katholt/plotTree) (Plotting trees with data using R and Python) is developed by Kat Holt - @DrKatHolt - <http://holtlab.net>.
This repository used example data of the `plotTree` to re-create figures generated by `plotTree.R`.
## Basic strain info
```{r warning=FALSE, fig.width=8, fig.height=8, message=FALSE}
source("01_basic_strain_info.R")
```
## Pan genome heatmap
```{r warning=FALSE, fig.width=12, fig.height=8, message=FALSE}
source("02_pan_genome_heatmap.R")
```
## Curated genes, coloured
```{r warning=FALSE, fig.width=9, fig.height=9, message=FALSE}
source("03_curated_genes.R")
```
## Plot tree with data
```{r warning=FALSE, fig.width=14, fig.height=8, message=FALSE}
# in case colnames start with numbers or contain dashes, which R does not like as column headers
snps<-read.csv("plotTree/tree_example_april2015/alleles.csv",header=F,row.names=1, stringsAsFactor=F)
snps_strainCols <- snps[1,] # column names = strain names
snps<-snps[-1,] # drop strain names
colnames(snps) <- snps_strainCols
gapChar <- "?"
snp <- t(snps)
lsnp <- apply(snp, 1, function(x) x != snp[1,] & x != gapChar & snp[1,] != gapChar)
lsnp <- as.data.frame(lsnp)
lsnp$pos <- as.numeric(rownames(lsnp))
lsnp <- tidyr::gather(lsnp, name, value, -pos)
## dataset 1
snp_data <- lsnp[lsnp$value, c("name", "pos")]
head(snp_data)
## dataset 2
bar_data <- read.csv("plotTree/tree_example_april2015/bar.csv")
head(bar_data)
library(ggtree)
info <- read.csv("info.csv")
tree <- read.tree("tree.nwk")
p <- ggtree(tree) %<+% info + geom_tippoint(aes(color=location))
facet_plot(p, panel="SNP", data=snp_data, geom=geom_point, mapping=aes(x=pos), pch='|', color="firebrick") %>%
facet_plot("BAR", bar_data, geom_segment, aes(x=0, xend=dummy_bar_value, y=y, yend=y)) + theme_tree2()
```