-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeatmaps.R
96 lines (81 loc) · 3.01 KB
/
Heatmaps.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
library(ggplot2)
library(viridisLite)
library(viridis)
library(dplyr)
library(hexbin)
library(dagitty)
library(ggdag)
#Plot species richness as a function of mean NDVI
plot(richness ~ mean_NDVI, data = test)
test <- data.frame(sp_rich23)
names(test) <- "richness"
test$mean_NDVI <- data.frame(predNDVI)[,1]
test$var_NDVI <- data.frame(var_res)[,1]
test$CV_NDVI <- data.frame(CV_ras)[,1]
test$richness <- as.numeric(test$richness)
test$mean_NDVI <- as.numeric(test$mean_NDVI)
test$var_NDVI <- as.numeric(test$var_NDVI)
# Create the hex plot (Mean_NDVI vs richness)
hex_plot <- ggplot(test, aes(x = mean_NDVI, y = richness)) +
geom_hex(aes(fill = ..count..), color = "white") +
scale_fill_viridis(option = "C", direction = -1, name = "Count") +
labs(title = "Hex Plot of Mean NDVI vs Richness",
x = "Mean NDVI",
y = "Richness") +
theme_light() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
panel.grid = element_blank())
plot(hex_plot)
# Save the hex plot to OneDrive
one_drive_path <- "~/Library/CloudStorage/OneDrive-UBC/Directed Studies/mean_NDVI_vs_richness_tile.png"
ggsave(one_drive_path,
plot = hex_plot,
width = 10,
height = 8,
dpi = 300)
# Create the violin plot
violin_plot <- ggplot(test, aes(x = factor(richness), y = mean_NDVI)) +
geom_violin(fill = "skyblue", alpha = 0.7) +
labs(title = "Violin Plot of Mean NDVI vs Species Richness",
x = "Species Richness",
y = "Mean NDVI") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Print the violin plot
print(violin_plot)
# Create the hex plot (var_NDVI vs richness)
hex_plot <- ggplot(test, aes(x = var_NDVI, y = richness)) +
geom_hex(aes(fill = ..count..), color = "white") +
scale_fill_viridis(option = "E", direction = -1, name = "Count") +
labs(title = "Hex Plot of variance in NDVI vs Richness",
x = "Variance in NDVI",
y = "Richness") +
theme_light() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
panel.grid = element_blank())
plot(hex_plot)
# Save the hex plot to OneDrive
one_drive_path <- "~/Library/CloudStorage/OneDrive-UBC/Directed Studies/var_NDVI_vs_richness_tile.png"
ggsave(one_drive_path,
plot = hex_plot,
width = 10,
height = 8,
dpi = 300)
# Create the hex plot (CV_NDVI vs richness)
hex_plot <- ggplot(test, aes(x = CV_NDVI, y = richness)) +
geom_hex(aes(fill = ..count..), color = "white") +
scale_fill_viridis(option = "D", direction = -1, name = "Count") +
labs(title = "Hex Plot of Coefficient of variation in NDVI vs Richness",
x = "Coefficient of variation in NDVI",
y = "Richness") +
theme_light() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
panel.grid = element_blank())
plot(hex_plot)
# Save the hex plot to OneDrive
one_drive_path <- "~/Library/CloudStorage/OneDrive-UBC/Directed Studies/CV_NDVI_vs_richness_tile.png"
ggsave(one_drive_path,
plot = hex_plot,
width = 10,
height = 8,
dpi = 300)