-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure 5 b and d.R
149 lines (101 loc) · 3.58 KB
/
figure 5 b and d.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
142
143
144
145
146
147
148
149
### Figure 5 (b)
## heatmap unequal rows and col with NA
### heatmap with automated legends
### heatmap2 and heatmaply and ggplot
muek = as.data.frame(heatmaps_rate)
colnames(muek)= c("Taxon","G.size","GC%","Repeat %", "C.G","T.G.C")
### ggplot
library(ggplot2)
library(hrbrthemes)
### ggplot requires a different data structure
### x vs y , fill = Z - this form
rownames(muek)= muek$Taxons
x1 = muek$Taxon
y2 = colnames(muek)
### removing unncesarry heading
y2 = as.vector(y2)
y2p = setdiff(y2,y2[1])
#x1 = y2p
###converting to vector form
muek1 = muek[,-1]
rownames(muek1)= muek$Taxon
z1 = c(muek1$G.size,muek1$GC,muek1$`Repeat %`,muek1$C.G,muek1$T.G.C)
a1 = nrow(muek1)
a2 = ncol(muek1)
a1a2 = a1*a2
z2vec = as.vector(z1)
### another way to create the required df
data2 = expand.grid(X = x1, Y = y2p)
data2$Z = z2vec
Z_val = data2$Z
data2$Z = log10(data2$Z)
colnames(data2)= c("Taxons","Parameters","log_P")
### plotting histgram with ggplot2
# Color Brewer palette
library(RColorBrewer)
library(tidyverse)
### RColorbrewer ueful only for discrete values
library(viridis)
p = ggplot(data2, aes(Parameters, Taxons, fill= log_P)) +
geom_tile()+
scale_fill_gradient(low="dark blue", high="white") +
theme_classic()+
scale_x_discrete(position = "top")+
scale_y_discrete(position = "left")+
ggtitle(label = "Genome parameters vs SNM rates(Taxon I)")+
theme(plot.title = element_text(hjust = 0.5,face = "bold",size = 8.5),
plot.subtitle = element_text(hjust = 0.5),
axis.title = element_text(face = "bold",size = 7))
p + theme(axis.text.x = element_text(size= 6.5 ,angle = 90),
axis.text.y = element_text(size= 6.5),
panel.border = element_rect(colour = "black", fill = NA, linewidth = 0.5))
ggsave(filename = "gpar vs SNM I.png",dpi = 360)
### Figure 5 (d)
muek = as.data.frame(heatmaps_rate)
colnames(muek)= c("Taxon","G.size","GC%","Repeat %", "C.G","T.G.C")
### ggplot
library(ggplot2)
library(hrbrthemes)
### ggplot requires a different data structure
### x vs y , fill = Z - this form
rownames(muek)= muek$Taxons
x1 = muek$Taxon
y2 = colnames(muek)
### removing unncesarry heading
y2 = as.vector(y2)
y2p = setdiff(y2,y2[1])
#x1 = y2p
###converting to vector form
muek1 = muek[,-1]
rownames(muek1)= muek$Taxon
z1 = c(muek1$G.size,muek1$GC,muek1$`Repeat %`,muek1$C.G,muek1$T.G.C)
a1 = nrow(muek1)
a2 = ncol(muek1)
a1a2 = a1*a2
z2vec = as.vector(z1)
### another way to create the required df
data2 = expand.grid(X = x1, Y = y2p)
data2$Z = z2vec
Z_val = data2$Z
data2$Z = log10(data2$Z)
colnames(data2)= c("Taxons","Parameters","log_P")
### plotting histgram with ggplot2
# Color Brewer palette
library(RColorBrewer)
library(tidyverse)
### RColorbrewer ueful only for discrete values
library(viridis)
p = ggplot(data2, aes(Parameters, Taxons, fill= log_P)) +
geom_tile()+
scale_fill_gradient(low="dark blue", high="white") +
theme_classic()+
scale_x_discrete(position = "top")+
scale_y_discrete(position = "left")+
ggtitle(label = "Genome parameters vs SNM rates(Taxon II)")+
theme(plot.title = element_text(hjust = 0.5,face = "bold",size = 8.5),
plot.subtitle = element_text(hjust = 0.5),
axis.title = element_text(face = "bold",size = 7))
p + theme(axis.text.x = element_text(size=6.5 ,angle = 90),
axis.text.y = element_text(size=6.5),
panel.border = element_rect(colour = "black", fill = NA, linewidth = 0.5))
ggsave(filename = "gpar vs SNM II.png",dpi = 360)