-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMaps_MiCoDaV2_2025.R
More file actions
141 lines (124 loc) · 5.09 KB
/
Copy pathMaps_MiCoDaV2_2025.R
File metadata and controls
141 lines (124 loc) · 5.09 KB
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
################################################################################
################################################################################
################################################################################
## MAPS
## sIBTEDS project
## https://rstudio.github.io/leaflet/markers.html
################################################################################
################################################################################
################################################################################
## Working Directory
getwd()
setwd("C:YOUR/WORKING/DIRECTORY")
################################################################################
################################################################################
################################################################################
## Packages
#install.packages("leaflet")
## to install the development version from Github, run
#install.packages("devtools")
library(devtools)
#devtools::install_github("rstudio/leaflet")
library(leaflet)
library(dplyr)
# Load required libraries
library(ggplot2)
library(sf)
#install.packages("rnaturalearth")
library(rnaturalearth)
#install.packages("rnaturalearthdata")
library(rnaturalearthdata)
#install.packages("ggthemes")
library(ggthemes)
################################################################################
################################################################################
################################################################################
## MiCODA V2 PRIMER V4 (COMPLETE)
# Load dataset
MiCoDaV2 <- read.csv("MiCoDaV2_PrimerV4_20250309.csv", sep = ",")
# Subset data
df.20 <- MiCoDaV2[1:41105,]
# Aggregate data to count samples per locality (longitude and latitude)
df.aggregated <- df.20 %>%
group_by(long, lat, environment_.biome.) %>%
summarise(sample_count = n(), .groups = "drop")
# Convert to an sf object for spatial plotting
df.sf <- st_as_sf(df.aggregated, coords = c("long", "lat"), crs = 4326)
# Load world map with gray background
world <- ne_countries(scale = "medium", returnclass = "sf")
# Define color mapping with a colorblind-friendly palette
color_map <- c(
"Water" = "#377eb8", # DodgerBlue
"Organism" = "#984ea3", # DarkOrange
"Other" = "#4daf4a", # LimeGreen
"Mineral" = "#ff7f00" # Crimson
)
# Create the map
ggplot() +
# Add world map in gray
geom_sf(data = world, fill = "gray90", color = "gray70") +
# Add sample points with color based on environment biome
geom_sf(data = df.sf, aes(size = sample_count, color = environment_.biome.), alpha = 0.7) +
scale_color_manual(values = color_map) + # Apply custom colors
scale_size_continuous(range = c(2, 12)) + # Adjust point sizes
theme_minimal() +
labs(
title = "MiCoDa Version 2.0",
subtitle = "Primer V4",
color = "Environment Biome",
size = "Sample Count"
) +
theme(
legend.position = "bottom",
legend.box = "horizontal",
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
plot.subtitle = element_text(hjust = 0.5, size = 12)
)
################################################################################
################################################################################
################################################################################
# MiCODA V2 PRIMER V4 (FILTERED BY QUALITY CHECK)
MiCoDaV2 <- read.csv("Metadata_MiCoDaV2_PrimerV4_20250310_V2.csv", sep = ",")
names(MiCoDaV2)
# Subset data
df.20 <- MiCoDaV2[1:32983,]
# Aggregate data to count samples per locality (longitude and latitude)
df.aggregated <- df.20 %>%
group_by(long, lat, environment_.biome.) %>%
summarise(sample_count = n(), .groups = "drop")
# Convert to an sf object for spatial plotting
df.sf <- st_as_sf(df.aggregated, coords = c("long", "lat"), crs = 4326)
# Load world map with gray background
world <- ne_countries(scale = "medium", returnclass = "sf")
# Define color mapping with a colorblind-friendly palette
color_map <- c(
"Water" = "#377eb8", # DodgerBlue
"Organism" = "#984ea3", # DarkOrange
"Other" = "#4daf4a", # LimeGreen
"Mineral" = "#ff7f00" # Crimson
)
# Create the map
ggplot() +
# Add world map in gray
geom_sf(data = world, fill = "gray90", color = "gray70") +
# Add sample points with color based on environment biome
geom_sf(data = df.sf, aes(size = sample_count, color = environment_.biome.), alpha = 0.7) +
scale_color_manual(values = color_map) + # Apply custom colors
scale_size_continuous(range = c(2, 12)) + # Adjust point sizes
theme_minimal() +
labs(
title = "MiCoDa Version 2.0",
subtitle = "Primer V4",
color = "Environment Biome",
size = "Sample Count"
) +
theme(
legend.position = "bottom",
legend.box = "horizontal",
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
plot.subtitle = element_text(hjust = 0.5, size = 12)
)
################################################################################
################################################################################
################################################################################
# END :)