-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFig01.Rmd
328 lines (258 loc) · 9.54 KB
/
Fig01.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
---
title: "Data analysis"
author: "Aoyue Bi, Daxing Xu"
date: "`r Sys.Date()`"
output:
html_document: # html_notebook, html_document
toc: true
toc_float:
toc_collapsed: true
toc_depth: 3
number_sections: true
theme: simplex # default, united, cerulean, journal, flatly, darkly, readable, spacelab, united, cosmo, lumen, paper, sandstone, simplex, and yeti
highlight: haddock # default, tango, pygments, kate, monochrome, espresso, zenburn, haddock, and breezedark
# bibliography: bibliography.json
---
# Fig1
```{r}
setwd("/Users/Aoyue/project/wheatVMapII/003_dataAnalysis/zz_rProject/R4VMap2Figs")
```
```{r setup, echo =F, message = T, warning = F}
library(tidyverse)
library(RColorBrewer)
library(ggpubr)
library(egg)
## eval 代码要不要运行
## echo 代码要不要输出
## include 图要不要输出
## warning 警告要不要输出
## message 默认Bin等信息要不要输出
```
## Fig1|World map
### 检查Taxa来自多少个国家
```{r}
df <- read_tsv("data/001_TaxaDB/WheatVMap2_GermplasmInfo.txt")
dfcountry <- df %>% filter(!is.na(orgCty)) %>% group_by(orgCty) %>% count()
numCountry <- nrow(dfcountry)
print(str_c("The sample in VMap2 project comes from ",numCountry," countries"))
### 按照亚群分类
df <- read_tsv("data/001_TaxaDB/WheatVMap2_GermplasmInfo.txt")
dfcountry <- df %>%
filter(!is.na(orgCty)) %>%
group_by(Subspecies_by6_TreeValidated,orgCty) %>% count() %>%
group_by(Subspecies_by6_TreeValidated) %>% count()
numCountry <- nrow(dfcountry)
print(str_c("The sample in VMap2 project comes from ",numCountry," countries"))
```
### map group by subspecies- 地图白色背景
- 726 个点是有经纬度信息的
```{r}
library(maps)
library(maptools)
df <- read_tsv("data/001_TaxaDB/WheatVMap2_GermplasmInfo.txt")
unique(df$Subspecies_by6_TreeValidated)
factorA <- c("Strangulata","Wild_emmer","Domesticated_emmer","Free_threshing_tetraploids","OtherTetraploids","Landrace","Cultivar","OtherHexaploids")
colB <- c("#87cef9","#ffd702","#7f5701","#016699","#00f3ff", "#fc6e6e","#9900ff","#fe63c2")
df$Subspecies_by6_TreeValidated <- factor(df$Subspecies_by6_TreeValidated,levels = factorA)
df <- df %>%
arrange(desc(Subspecies_by6_TreeValidated)) %>%
filter(!is.na(Longitude))
mp<-NULL #定义一个空的地图
# 注意: borders函数中的colour是地图国家边界线的颜色,fill是国家的填充颜色
# mapworld<-borders("world",colour = "#dedfe0",fill="#dedfe0") #绘制基本地图
# fcfcfc
mapworld<-borders("world",colour = "#f6f6f6",fill="#f6f6f6") #绘制基本地图, 白色背景
mpvoid<-ggplot()+mapworld + ylim(-55,90)+theme_void()
# mpvoid
mp<-mpvoid+
geom_point(data=df,
aes(x=df$Longitude,y=df$Latitude,fill = df$Subspecies_by6_TreeValidated),
shape=21,color="gray",stroke = 0.08,
alpha=0.75,size=2.5)+
scale_fill_manual(values = colB)+
theme(legend.position = 'none')
mp
# ggsave(mp,filename = "~/Documents/test.pdf", height = 4,width = 10)
ggsave(mp,filename = "~/Documents/test.pdf", height = 2.76 ,width = 6.89)
# ggsave(mp,filename = "~/Documents/test.png", height = 2.76 ,width = 6.89)
```
#### ====
## Fig.1\|PopNum barplot
```{r}
Subspecies <- c("Ae.tauschii","Wild emmer","Domesticated emmer","Free-threshing tetraploids",
"Other tetraploid","Landrace","Cultivar","Other hexaploid")
n <- c(36,91,52,50,19,306,223,285)
id <- rep(1,8)
df <- data.frame(id=id,Subspecies=Subspecies,n=n)
head(df)
df
colB <- c('#87cef9','#fe63c2','#9900ff','#fc6e6e','#00f3ff','#016699','#7f5701','#ffd702')
df$Subspecies <- factor(df$Subspecies,
levels = c( "Ae.tauschii","Other hexaploid","Cultivar","Landrace", "Other tetraploid",
"Free-threshing tetraploids", "Domesticated emmer","Wild emmer"))
p <- ggplot(df,aes(x=id,y=n,fill=Subspecies))+
geom_bar(stat="identity",alpha=0.95)+
scale_fill_manual(values = colB)+
coord_flip()+
theme_void()+
theme(legend.position = 'none')
p
ggsave(p,filename = "~/Documents/test.pdf",height = 0.5,width = 4)
```
### pie plot
```{r}
# Create Data
data <- data.frame(
group=c('AABBDD','AABB','DD'),
value=c(814,212,36)
)
# Compute the position of labels
data <- data %>%
arrange(desc(group)) %>%
mutate(prop = value / sum(data$value) *100) %>%
mutate(ypos = cumsum(prop)- 0.5*prop )
# Basic piechart
p <- ggplot(data, aes(x="", y=prop, fill=group)) +
geom_bar(stat="identity", width=1, color="white") +
coord_polar("y", start=0) +
theme_void() +
theme(legend.position="none") +
geom_text(aes(y = ypos, label = group), color = "black", size=3) +
scale_fill_manual(values = c("#ffd702",'#fc6e6e','#87cef9'))
p
ggsave(p,filename = "/Users/Aoyue/Documents/test.pdf",height = 2.57,width = 2.57)
```
#### =================
## LD
### Data import
```{r}
table_ploidy <- read.delim("data/012_LD/LD.ploid.txt.gz")
table_subspecies <- read.delim("data/012_LD/LD.subspecies.txt.gz")
table_subgenome <- read.delim("data/012_LD/LD.subgenome.txt.gz")
```
### only hexaploid by subgenome
```{r}
colB <- c("#fd8582","#967bce","#4bcdc6")
p <- table_subgenome %>%
mutate(Ploidy = factor(Ploidy,levels = c("tetraploid","hexaploid","diploid"),labels = c("AABB","AABBDD","DD"))) %>%
mutate(Sub=factor(Sub,levels = c("AA","BB","DD"),labels = c("A","B","D"))) %>%
filter(Ploidy == "AABBDD") %>%
slice_sample(prop = .1) %>%
ggplot(aes(x=window_kb/1000,y=meanOfR2, color=Sub, fill=Sub))+
# geom_point(alpha=0.05)+
# geom_smooth()+
stat_smooth(method = "gam", formula = y ~ s(x,k=110),span = 0.2, size = 1,se=T) +
scale_color_manual(values = colB)+
labs(x="Pairwise distance (Mb)", y=expression("Mean"~italic(r)^2))+
theme_classic()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(size=0.3, colour = "black"),
legend.position = 'none',text = element_text(size = 8))
p
ggsave(p,filename = "~/Documents/test.pdf",height = 2.4 ,width = 3.23)
# ggsave(p,filename = "~/Documents/test.pdf",height = 1.6 ,width = 1.76)
```
### claculate the r2
```{r}
dfnew <- table_subgenome %>% filter(Ploidy=="hexaploid")
```
```{r}
df1 <- dfnew %>%
filter(Sub == "AA") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
### 7662.08 kb
df2 <- dfnew %>%
filter(Sub == "BB") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
### 460.2692 kb
df3 <- dfnew %>%
filter(Sub == "DD") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
### 4404.953 kb
mean(df1$window_kb)
mean(df2$window_kb)
mean(df3$window_kb)
```
### by subspecies
```{r}
# unique(table_subspecies$Group)
factorA <- c("wildEmmer","domesticatedEmmer","freeThreshTetraploid","landrace","cultivar","tauschii")
labelsA <- c("WE","DE","FTT","LR","CL","AT")
colB <- c("#ffd702","#7f5701","#016699", "#fc6e6e","#9900ff","#87cef9")
p <- table_subspecies %>%
mutate(group=factor(Group,levels=factorA,labels=labelsA)) %>%
group_by(group) %>%
slice_sample(prop = .1) %>%
ggplot(aes(x=window_kb/1000,y=meanOfR2, color=group, fill=group))+
# geom_point(alpha=0.05)+
# geom_smooth(se = T)+
stat_smooth(method = "gam", formula = y ~ s(x,k=110),span = 0.2, size = 1,se=T) +
# geom_line(size=0.0001,alpha=0.9)+
scale_color_manual(values = colB)+
labs(x="Pairwise distance (Mb)", y=expression("Mean"~italic(r)^2))+
scale_x_continuous(limits = c(0,20))+
theme_classic()+
theme(panel.grid = element_blank(),
panel.background = element_blank(),
axis.line = element_line(size=0.3, colour = "black"),
legend.position = 'none',
text = element_text(size = 8))
p
# ggsave(p,filename = "~/Documents/test.pdf",height = 1.6 ,width = 1.76)
ggsave(p,filename = "~/Documents/test.pdf",height = 2.4 ,width = 3.23)
```
### claculate the r2
```{r}
df1 <- table_subspecies %>%
filter(Group=="landrace") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
df2 <- table_subspecies %>%
filter(Group=="cultivar") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
df3 <- table_subspecies %>%
filter(Group=="wildEmmer") %>%
filter(meanOfR2 > 0.19, meanOfR2 < 0.2)
df4 <- table_subspecies %>%
filter(Group=="domesticatedEmmer") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
df5 <- table_subspecies %>%
filter(Group=="freeThreshTetraploid") %>%
filter(meanOfR2 > 0.49, meanOfR2 < 0.5)
df6 <- table_subspecies %>%
filter(Group=="tauschii") %>%
filter(meanOfR2 > 0.19, meanOfR2 < 0.2)
mean(df1$window_kb)
mean(df2$window_kb)
mean(df3$window_kb)
mean(df4$window_kb)
mean(df5$window_kb)
mean(df6$window_kb)
```
```{r}
# unique(table_subspecies$Group)
factorA <- c("wildEmmer","domesticatedEmmer","freeThreshTetraploid","landrace","cultivar","tauschii")
labelsA <- c("WE","DE","FTT","LR","CL","AT")
colB <- c("#ffd702","#7f5701","#016699", "#fc6e6e","#9900ff","#87cef9")
p <- table_subspecies %>%
mutate(group=factor(Group,levels=factorA,labels=labelsA)) %>%
group_by(group) %>%
slice_sample(prop = .1) %>%
filter(group=="LR") %>%
ggplot(aes(x=window_kb/1000,y=meanOfR2, color=group, fill=group))+
# geom_point(alpha=0.05)+
# geom_smooth(se = T)+
stat_smooth(method = "gam", formula = y ~ s(x,k=110),span = 0.2, size = 1,se=T) +
# geom_line(size=0.0001,alpha=0.9)+
scale_color_manual(values = colB)+
labs(x="Pairwise distance (Mb)", y=expression("Mean"~italic(r)^2))+
scale_x_continuous(limits = c(0,20))+
theme_classic()+
theme(panel.grid = element_blank(),
panel.background = element_blank(),
axis.line = element_line(size=0.3, colour = "black"),
legend.position = 'none',
text = element_text(size = 8))
p
ggsave(p,filename = "~/Documents/test.pdf",height = 1.6 ,width = 1.76)
```