/
Plot_imp.r
131 lines (103 loc) · 4.57 KB
/
Plot_imp.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
### Importance plot for Random Forest
size.title = 15
line.lwd = 1
size.label.x = 16
size.text.x = 16
size.point = 4
size.label.y = 16
size.text.y = 14
size.legend.text = 15
size.legend.title = 20
unit.legend.h = 1.8
unit.legend.w = 1.8
size.ann = 10
colour.axis = "gray20"
colour.theme = "black"
colour.axis.line = "gray20"
colour.line = "gray50"
label.T = "Heterozygosity"
max_size_dot = 8
leg.x = 0.15
leg.y = 0.15
## Theme to be used for all plots
theme.pop = theme(plot.title = element_text(lineheight=.8, face="bold", size = size.title,hjust = 0.5),
plot.background = element_blank()
,panel.grid.major = element_blank()
,panel.grid.minor = element_blank()
,panel.border = element_blank()
,panel.background = element_blank(),
axis.line = element_line(color = 'black'),
plot.margin = unit(c(0.5,0.5,0.5,0.5), "cm"),
axis.title.x = element_text(size=size.label.x,vjust=-2),
axis.text.x = element_text(size=size.text.x, vjust = 0.5),
axis.title.y = element_text(size=size.label.x, vjust = 2),
axis.text.y = element_text(size=size.text.x),
legend.title = element_blank(),
legend.text = element_text(size = size.legend.text),
legend.spacing.y = unit(5,"cm"),
legend.position = c(leg.x, leg.y),
legend.key = element_rect(fill = "white", size = 5),
legend.key.size = unit(1.5,"lines"))
ext.rf.full = readRDS("ext.rf.full.RDS")
imp = (varImp(ext.rf.full,)$importance)
imp = data.frame(var = rownames(imp), importance = imp$Overall)
imp$var = as.factor(imp$var)
imp = imp %>% mutate(var = recode(var, "min_pop_win" = "min(pop)",
"mean_pop_win" = "mean(pop)",
"max_pheno_dist_win" = "max(pheno_d)",
"mean_pheno_dist_win" = "mean(pheno_d)",
"max_opt_win" = "max(opt)",
"cat_winy" = "extreme",
"age.sex.mat" = "repro",
"sons.mean" = "fec",
"sel" = "sel"))
min_n_lab = bquote(paste("min(", italic('N'),")"))
mean_n_lab = bquote(bar(italic('N')))
max_pheno_d_lab= bquote(paste("max(", italic(Theta), " - ", italic('z'),")"))
mean_pheno_d_lab = bquote(paste("mean(", italic(Theta), " - ", italic('z'),")"))
max_opt_lab = bquote(paste("max(", italic(Theta), ")"))
extreme_lab = bquote(italic('E'))
repro_lab = bquote(italic(a)[f])
fec_lab = bquote(italic(lambda)[0])
sel_lab = bquote(italic('s'))
tt = data.frame(x = as.factor(1:2), y = 1:10)
ggplot(data = tt, aes(x= x, y = y)) +
scale_x_discrete(labels = c(min_n_lab,fec_lab))
plot_imp_full = ggplot(data = imp, aes(x=reorder(var,importance), y=importance)) +
geom_point(size = size.point) +
geom_segment(aes(x=var,xend=var,y=0,yend=importance)) +
ylab("Importance") +
xlab("") +
scale_x_discrete(labels = c(sel_lab,fec_lab,repro_lab,extreme_lab,max_opt_lab,mean_pheno_d_lab,max_pheno_d_lab,mean_n_lab,min_n_lab)) +
theme.pop +
coord_flip()
ext.rf.full = readRDS("ext.rf.base.RDS")
imp = (varImp(ext.rf.full,)$importance)
imp = data.frame(var = rownames(imp), importance = imp$Overall)
imp$var = as.factor(imp$var)
imp = imp %>% mutate(var = recode(var, "min_pop_win" = "min(pop)",
"mean_pop_win" = "mean(pop)",
"max_pheno_dist_win" = "max(pheno_d)",
"mean_pheno_dist_win" = "mean(pheno_d)",
"max_opt_win" = "max(opt)",
"cat_winy" = "extreme",
"age.sex.mat" = "repro",
"sons.mean" = "fec",
"sel" = "sel"))
plot_imp_red = ggplot(data = imp, aes(x=reorder(var,importance), y=importance)) +
geom_point(size = size.point) +
geom_segment(aes(x=var,xend=var,y=0,yend=importance)) +
ylab("Importance") +
xlab("") +
scale_x_discrete(labels = c(sel_lab,max_opt_lab,extreme_lab,max_pheno_d_lab, mean_pheno_d_lab,repro_lab,fec_lab)) +
theme.pop +
coord_flip()
# ext.gam.full = readRDS("ext.gam.full.RDS")
#
# plot(ext.gam.full)
Plot_imp = plot_grid(plot_imp_full,
plot_imp_red,
labels = c("(a)", "(b)"),
nrow = 1, align = "v",hjust = -5)
Plot_imp
# 15 7