-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSC_WheatOrigin.R
141 lines (123 loc) · 3.77 KB
/
SC_WheatOrigin.R
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
library(tidyverse)
library(sf)
data <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-04-18/founder_crops.csv')
worldmap <- st_as_sf(maps::map(database="world", plot = FALSE, fill = TRUE))
# Soft wheat (="Child"), hexaploids
soft <- c("Triticum aestivum")
# Hard wheat (="Parent 1"), tetraploids
durum <- c("Triticum turgidum","Triticum dicoccum", "Triticum durum")
# Wild grass: Aegilops tauschii (="Parent 2"), diploids
wild <- c("Aegilops")
# Add column with a "type" element
# (soft wheat, hard wheat or aegilops)
clean<-data%>%
mutate(
type=case_when(
str_detect(taxon_detail,paste(soft, collapse = "|"))~"Soft_wheat",
str_detect(taxon_detail,paste(durum, collapse = "|"))~"Durum_wheat",
str_detect(taxon_detail,paste(wild, collapse = "|"))~"Aegilops"
)
)%>%
drop_na(type)
# Select all sites with one, two or three crops present
all_sites<-clean%>%pull(site_name)
# Select only sites with the three crops present
venn<-clean%>%
select(site_name,age_start,type)%>%
group_by(site_name,type)%>%
filter(age_start==min(age_start))%>%
ungroup()%>%
distinct()%>%
select(site_name,type)%>%
mutate(ct=1)%>%
pivot_wider(names_from=type,values_from=ct,values_fill=0)%>%
mutate(cl=case_when(
# Single class
(Aegilops==1)&(Durum_wheat==0)&(Soft_wheat==0)~"A",
(Aegilops==0)&(Durum_wheat==1)&(Soft_wheat==0)~"B",
(Aegilops==0)&(Durum_wheat==0)&(Soft_wheat==1)~"C",
# Double class
(Aegilops==1)&(Durum_wheat==1)&(Soft_wheat==0)~"D",
(Aegilops==0)&(Durum_wheat==1)&(Soft_wheat==1)~"E",
(Aegilops==1)&(Durum_wheat==0)&(Soft_wheat==1)~"F",
# Triple class
(Aegilops==1)&(Durum_wheat==1)&(Soft_wheat==1)~"G"
))
res <- venn%>%
mutate(ct=1)%>%
group_by(cl)%>%
summarize(sm=sum(ct))
# Select only sites with the three crops present
sel_sites<-clean%>%
select(site_name,age_start,type)%>%
group_by(type,site_name)%>%
filter(age_start==min(age_start))%>%
ungroup()%>%
distinct()%>%
mutate(ct=1)%>%
group_by(site_name)%>%
summarize(sm=sum(ct))%>%
filter(sm==3)%>%
pull(site_name)
# Only two sites with the three crops
sel_sites
rar<-clean%>%
filter(site_name%in%sel_sites)
coords_all<-clean%>%
select(site_name,latitude,longitude)%>%
#filter(site_name%in%all_sites)%>%
distinct()%>%
left_join(venn)
projcrs <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
coords_sf <- st_as_sf(
x = coords_all,
coords = c("longitude", "latitude"),
crs = projcrs
)
bbox_x = c(28,60)
bbox_y = c(29,41)
back <- "#1D201F"
land <- "grey20"
pal<-c(
"A"= "#E09B33",
"B"= "#EA3D32",
"D"= "#E05A33",
"E"= "#6A45A2",
"G"= "white"
)
ggplot()+
geom_sf(worldmap,mapping=aes(geometry=geom),fill=land,color=NA)+
geom_sf(
coords_sf%>%filter(cl!="G"),
mapping=aes(geometry=geometry,color=cl),
alpha=0.8,size=2
)+
geom_sf(
coords_sf%>%filter(cl=="G"),
mapping=aes(geometry=geometry),
pch=21,color="black",fill="white",
alpha=1,size=4
)+
geom_sf_text(
coords_sf%>%filter(cl=="G"),
mapping=aes(geometry=geometry,label=site_name),
pch=21,color="black",fill="white",
alpha=1,size=4
)+
guides(color="none")+
#geom_sf(coords_sf%>%filter(site_name%in%sel_sites),mapping=aes(geometry=geometry))+
#geom_sf(coords_sf%>%filter(site_name%in%sel_sites[1]),mapping=aes(geometry=geometry))+
scale_x_continuous(limits=bbox_x)+
scale_y_continuous(limits=bbox_y)+
scale_color_manual(values=pal)+
theme_void()+
theme(
plot.background = element_rect(fill=back,color=NA)
)
ggsave(
filename="wheat_map.png",
width=25,
height=15,
unit="cm",
dpi=320
)