-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 21.1 KB
/
.Rhistory
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
latitude <- sapply(coordinates, function(x) as.numeric(x[2]))
map_data <- data.frame(longitude, latitude, abundance)
map_data <- na.omit(map_data) %>%
filter(longitude > -180 & longitude < 180 & latitude > -90 & latitude < 90)
world_map <- map_data("world")
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray")+
geom_point(data=map_data, aes(x=longitude, y= latitude,size=abundance))+
theme_bw()
summary(map_data)
map_data
data <- data %>% filter(!is.na(.[[ncol(data)]]))
data_soil <- data %>% tibble() %>% filter(ifelse('soil' %in% X1_y || 'Soil' %in% X2_y, TRUE, FALSE))
abundance <- as.numeric(gsub("%", "",data_soil[,5]))
coordinates <- strsplit(as.character(data_soil[,13]), ' ') %>% tibble()
longitude <- sapply(coordinates, function(x) as.numeric(x[1]))
data <- data %>% filter(!is.na(.[[ncol(data)]]))
data_soil <- data %>% tibble() %>% filter(ifelse('soil' %in% X1_y | 'soil' %in% X2_y, TRUE, FALSE))
abundance <- as.numeric(gsub("%", "",data_soil[,5]))
coordinates <- strsplit(as.character(data_soil[,13]), ' ')
coordinates_df <- tibble(
longitude = sapply(coordinates, function(x) as.numeric(x[1])),
latitude = sapply(coordinates, function(x) as.numeric(x[2]))
)
map_data <- data.frame(longitude, coordinates_df)
map
map_data
coordinates_df
coordinates
coordinates <- strsplit(as.character(data_soil[,13]), '\ ')
data <- read.csv('./dwde2xd2.csv')
data <- read.csv('./dwde2xd2.csv')
data <- read.csv('./dwde2xd2.csv')
data <- read.csv('./dwde2xd2.csv')
world_map <- map_data("world")
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lot,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
data
data %>% head()
world_map <- map_data("world")
ggplot() +
geom_polygon(data = world_map,
aes(x = lon, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lot,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
world_map <- map_data("world")
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
world_map <- map_data("world")
# reduce the NA in last column
data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
# ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
data %>% head()
data <- read.csv('./dwde2xd2.csv')
raw_data <- read.csv('./dwde2xd2.csv')
data=raw_data
world_map <- map_data("world")
# reduce the NA in last column
data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
# ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
data=raw_data
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
data %>% head()
data=raw_data %>% select('abundance','lon','lat')
data %>% head()
data %>% drop_na()->data
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
# geom_polygon(data = world_map,
# aes(x = long, y = lat, group = group),
# fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
data %>% head()
# change abundace to numeric from precentage
data %>% drop_na() %>% mutate(abundance = as.numeric(abundance)) -> data
# change abundace to numeric from precentage
data %>% mutate(abundance = as.numeric(abundance)) %>% drop_na() -> data
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
# geom_polygon(data = world_map,
# aes(x = long, y = lat, group = group),
# fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
# ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
data=raw_data %>% select('abundance','lon','lat')
# change abundace to numeric from precentage
data %>% drop_na()
# change abundace to numeric from precentage
data %>% drop_na() %>% mutate(abundance = as.numeric(abundance))
# change abundace to numeric from precentage
data %>% drop_na() %>% as.numeric(gsub("%", "", data$abundance)) / 100
# change abundace to numeric from precentage
data %>% drop_na() %>% as.numeric(gsub("%", "", data$abundance))
data=raw_data %>% select('abundance','lon','lat')
# change abundace to numeric from precentage
data %>% drop_na() %>% as.numeric(gsub("%", "", data$abundance))
# as.numeric(gsub("%", "", df$percentage_column)) / 100
data
data=raw_data %>% select('abundance','lon','lat') %>% drop_na()
# as.numeric(gsub("%", "", df$percentage_column)) / 100
data
# as.numeric(gsub("%", "", df$percentage_column)) / 100
data$abundance <- as.numeric(gsub("%", "", data$abundance)) / 100
data
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
# geom_polygon(data = world_map,
# aes(x = long, y = lat, group = group),
# fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
# ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance (%)", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
# ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat, size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
data
raw_data
raw_data
raw_data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'Soil',ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
# as.numeric(gsub("%", "", df$percentage_column)) / 100
data$abundance <- as.numeric(gsub("%", "", data$abundance)) / 100
data
data %>% summary()
data %>% summarise()
data %>% group_by(env) %>% summarise()
data=raw_data %>% select('abundance','lon','lat') %>% drop_na()
raw_data %>% mutate(env=ifelse('soil' %in% env1,'soil',ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
# as.numeric(gsub("%", "", df$percentage_column)) / 100
data$abundance <- as.numeric(gsub("%", "", data$abundance)) / 100
data %>% group_by(env) %>% summarise()
raw_data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'soil','dwgc'))
raw_data %>% mutate(env=ifelse('soil' %in% env1,'soil','dwgc'))
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'soil','dwgc')) %>% select('env','abundance','lon','lat') %>% unique()
raw_data %>% mutate(env=ifelse('soil' %in% env1,'soil','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data
raw_data %>% mutate(env=ifelse(soil %in% env1,'soil','dwgc')) %>% select('env') %>% unique()
raw_data %>% mutate(env=if("soil" %in% env1,'soil','dwgc')) %>% select('env') %>% unique()
raw_data %>% mutate(env=if('soil' %in% env1,'soil','dwgc')) %>% select('env') %>% unique()
raw_data %>% mutate(env=if('soil' %in% env1,'soil','dwgc')) %>% select('env') %>% unique()
raw_data %>%
mutate(env = if("soil" %in% env1, "soil", "dwgc")) %>%
# 检查env1向量中是否包含"soil"
env_value <- if("soil" %in% env1, "soil", "dwgc")
raw_data %>% mutate(env=ifelse('soil' %in% env1,'soil','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('soil' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('gut' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('gut' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env=ifelse('animal' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
if (nrow(raw_data) == length(env1)) {
# 使用tidyverse的管道操作符进行数据转换
raw_data <- raw_data %>%
mutate(env = ifelse(env1 == "soil", "soil", "dwgc")) %>%
distinct(env) # 使用distinct而不是select和unique,以获取唯一的env值
} else {
warning("raw_data的行数与env1的长度不匹配。")
}
raw_data %>% mutate(env=if_else('animal' %in% env1,'111','dwgc')) %>% select('env') %>% unique()
# ifelse('aquatic' %in% env1,'Water',ifelse('animal' %in% env1,'Animal',NA)))) %>% select('env','abundance','lon','lat') %>% drop_na() -> data
raw_data %>% mutate(env = if_else(str_detect(env1, "soil"), "soil", env)) %>% select('env') %>% unique()
data <- row_data %>% select('env1_split_1','abundance','lon','lat') %>% drop_na()
data <- raw_data %>% select('env1_split_1','abundance','lon','lat') %>% drop_na()
# as.numeric(gsub("%", "", df$percentage_column)) / 100
data$abundance <- as.numeric(gsub("%", "", data$abundance)) / 100
data %>% group_by(env1_split_1) %>% summarise(mean_abundance=mean(abundance))
color_scheme <- c("#AFD888", "#63ADD0", "#FF4540", "#D836C4", "#EE6B9E", "#FF8F40", "#FFFA73", "#00A779")
world_map <- map_data("world")
# reduce the NA in last column
# data <- data[complete.cases(data),]
ggplot() +
geom_polygon(data = world_map,
aes(x = long, y = lat, group = group),
fill = "lightgray", color = "gray") +
geom_point(data = data, aes(x = lon,
y = lat,
fill=factor(env1_split_1),
size = abundance),
alpha = 0.5, shape = 21,
color = 'grey40', stroke = 0.5) +
scale_size_continuous(name = "Node size for relative abundance", guide = guide_legend(override.aes = list(color = "black",fill="black"))) +
scale_fill_manual(values = color_scheme,
name = "Node color for sample environmental type", guide = guide_legend(override.aes = list(size = 6)))
labs(x = "longitude", y = "latitude") +
theme_bw() +
NULL
ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
ggsave("world.pdf",units = "in",width = 17.27, height = 6.8)
library(readr)
library(dplyr)
library(tidyverse)
# Load the data
file_path <- './dwde2xd2.csv'
data <- read_csv(file_path) %>%
mutate(abundance_numeric = parse_number(abundance))
library(readr)
library(dplyr)
library(tidyverse)
# Load the data
file_path <- '../dwde2xd2.csv'
data <- read_csv(file_path) %>%
mutate(abundance_numeric = parse_number(abundance))
# mutate(offspring_none=ifelse(Offspring_Numbers==0,0,1)) %>%
# glm(offspring_none ~ Age+mating+Age*mating, family=binomial, data=.) %>%
# summary() %>% .$coefficients %>%
# kable(format = "markdown", caption="Coefficients of the binomial model (Age+mating+Age*mating)")
data %>%
mutate(abundance_numeric_2=ifelse(abundance_numeric==0,0,1)) %>%
filter(!is.na(env1_split_1)) %>%
glm(abundance_numeric_2 ~ env1_split_1, family=binomial, data=.) %>%
summary()
# Plot the violin Plot
data %>% filter(abundance_numeric >0) %>% filter(!is.na(env1_split_1)) %>%
ggplot(aes(x = env1_split_1, y = log(abundance_numeric + 1))) +
geom_violin() +
geom_boxplot(width = 0.2, aes(fill=env1_split_1)) +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")+
theme_bw()
# Convert 'abundance' from percentage to numeric
# Select environments for analysis
selected_envs <- c('plant', 'animal', 'soil','aquatic')
filtered_data <- data %>%
filter(env1 %in% selected_envs) %>%
mutate(env1 = str_split(env1, ";" , simplify = TRUE)[, 1]) %>%
mutate(env1 = str_replace(env1, "\\|", ";"))
# Plot the boxplot for abundance in the selected environments
ggplot(filtered_data, aes(x = env1, y = log(abundance_numeric + 1))) +
geom_boxplot() +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")+
theme_bw()
filtered_data
filtered_data %>%
ggplot(aes(x = env1, y = log(abundance_numeric + 1))) +
geom_violin() +
geom_boxplot(width = 0.1) +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")
filtered_data %>% lm(log(abundance_numeric + 1) ~ env1, data = .) %>%
broom::tidy() %>%
ggplot(aes(x = term, y = estimate)) +
geom_col() +
coord_flip() +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")
filtered_data %>% lm(log(abundance_numeric + 1) ~ env1, data = .) %>%
summary()
filtered_data %>% lm(log(abundance_numeric + 1) ~ env1, data = .) %>%
anova()
filtered_data %>% lm(log(abundance_numeric + 1) ~ env1, data = .) %>%
broom::tidy() %>% select(term, estimate, p.value)
data %>%
filter(!is.na(env1_split_2)) %>%
ggplot(aes(x = env1_split_2, y = log(abundance_numeric + 1))) +
geom_violin() +
geom_boxplot(width = 0.2, aes(fill=env1_split_2)) +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")+
theme_bw()
# Draw the forest plot
# data %>%
# filter(!is.na(env1_split_2)) %>%
# lm(log(abundance_numeric + 1) ~ env1_split_2, data = .) %>%
# broom::tidy() %>%
# ggplot(aes(x = term, y = estimate)) +
# geom_col() +
# coord_flip() +
# labs(title = "Abundance Boxplot for Selected Environments",
# x = "Environment",
# y = "Abundance")
# Draw forest plot
data %>%
filter(!is.na(env1_split_2)) %>%
lm(log(abundance_numeric + 1) ~ env1_split_2, data = .) %>%
summary()
data %>%
filter(!is.na(env1_split_2)) %>%
lm(log(abundance_numeric+1) ~ env1_split_2, data = .) -> model
model %>% plot(which = c(1,2,3,5))
model %>% anova()
model %>% broom::tidy() %>%
ggplot(aes(x = term, y = estimate)) +
geom_col() +
coord_flip() +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")
library(rattle)
rattle()
filtered_data %>%
ggplot(aes(x = env1, y = log(abundance_numeric + 1))) +
geom_violin() +
geom_boxplot(width = 0.1) +
labs(title = "Abundance Boxplot for Selected Environments",
x = "Environment",
y = "Abundance")+
theme_bw()
library(ggtree)
library(ape)
library(ggplot2)
# 读取树文件
tree <- read.tree("./tree/tree/alignment1.fasta.treefile")
library(ggtree)
library(ape)
library(ggplot2)
# 读取树文件
tree <- read.tree("./tree/tree/alignment1.fasta.treefile")
# 读取树文件
tree <- read.tree("./tree/tree/alignment.fasta.treefile")
# 读取树文件
tree <- read.tree("./tree/tree/alignment_unique.fasta.treefile")
# 绘制基础系统发育树
p <- ggtree(tree)
# 美化树的外观
p <- p +
geom_tiplab(size=3, align=TRUE) + # 增加标签并对齐
theme_tree2() + # 使用树的主题
labs(title="Phylogenetic Tree") # 添加标题
# 打印绘图
print(p)
dist_matrix <- cophenetic(tree)
# 计算每个样本与其他所有样本的平均距离
mean_distances <- rowMeans(dist_matrix)
# 找出平均距离最大的前三个样本
top3_samples <- names(sort(mean_distances, decreasing = TRUE))[1:3]
cat("差异性最大的前 3 个样本是:", top3_samples, "\n")
# 删除这三个样本
pruned_tree <- drop.tip(tree, top3_samples)
# 绘制新的系统发育树
plot(pruned_tree, main = "Pruned Phylogenetic Tree")
# 获取叶节点的标签
tip_labels <- tree$tip.label
# 找出平均距离最大的前三个样本
top3_samples <- names(sort(mean_distances, decreasing = TRUE))[1:5]
cat("差异性最大的前 3 个样本是:", top3_samples, "\n")
# 删除这三个样本
pruned_tree <- drop.tip(tree, top3_samples)
# 绘制新的系统发育树
plot(pruned_tree, main = "Pruned Phylogenetic Tree")
# 找出平均距离最大的前三个样本
top3_samples <- names(sort(mean_distances, decreasing = TRUE))[1:9]
cat("差异性最大的前 3 个样本是:", top3_samples, "\n")
# 删除这三个样本
pruned_tree <- drop.tip(tree, top3_samples)
# 绘制新的系统发育树
plot(pruned_tree, main = "Pruned Phylogenetic Tree")
# 获取叶节点的标签
tip_labels <- tree$tip.label
# 获取内部节点的标签(如果有)
node_labels <- tree$node.label
# 输出叶节点的标签
cat("叶节点的标签是:\n")
print(tip_labels)
# 输出内部节点的标签
cat("内部节点的标签是:\n")
print(node_labels)