-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_abundance.Rmd
79 lines (52 loc) · 1.67 KB
/
map_abundance.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
---
title: "map_abundance"
author: "Yiheng Du"
date: "2023-12-10"
output: html_document
---
# Load the relevant packages
```{r, include=FALSE}
library(readxl)
library(tidyverse)
library(openxlsx)
library(ggpubr)
library(maps)
library(broom)
library(reshape2)
library(pheatmap)
```
# Import loaction and environment file
```{r}
raw_data <- read.csv('./dwde2xd2.csv')
```
```{r}
raw_data
```
```{r}
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
```
```{r}
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)
```