-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSD_plotting.R
82 lines (73 loc) · 5.31 KB
/
PSD_plotting.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
library(tidyverse)
library(FCSplankton)
setwd("PATH/TO/PROJECT/")
## Read in PSD data
project <- basename(getwd())
PSD_all <- read_csv(paste0("Influx_", project,"_PSD.csv"))
PSD_all[1:3,]
## Summarize PSD across sample replicates
PSD_all <- PSD_all %>%
dplyr::select(-sample,-time,-file,-stain,-flag,-replicate,-comments,-volume) %>% # remove columns that would inhibit averaging across replicates
dplyr::group_by(station,depth,Qc,pop) %>%
summarize_all(function(x) mean(x, na.rm=T)) %>%
arrange(station)
## Create station position labels
PSD_all$lat <- trunc(PSD_all$lat *10^2)/10^2
PSD_all$lon <- trunc(PSD_all$lon*10^2)/10^2
PSD_all$position <- paste0("St. ",PSD_all$station," (",PSD_all$lat,",",PSD_all$lon,")")
PSD_all$position <- as_factor(PSD_all$position)
## Set population group colors
group_colors <- c(bacteria = "lightsalmon1",
prochloro=viridis::viridis(4)[1],
synecho=viridis::viridis(4)[2],
picoeuk=viridis::viridis(4)[3])
## Plot all pop distributions with height allow biomass comparisons across population
PSD_all %>%
group_by(position,depth) %>%
ggplot() +
ggridges::geom_density_ridges(aes(x = Qc, y = -depth, height = biomass_per_bin, fill =pop, group = interaction(depth,pop)), stat="identity", color="darkgrey", alpha=0.55,size=.15,panel_scaling=FALSE) + # panel_scaling=TRUE relative scaling is calculated separately for each panel. panel_scaling=FALSE, relative scaling is calculated globally
scale_x_continuous(trans = "log10") +
scale_fill_manual(name = 'Population', values = group_colors, breaks = c("bacteria",'prochloro','synecho',"picoeuk"), labels = c("Bacteria",'Pro','Syn',"Picoeuk")) +
theme(legend.key.size = unit(.35, 'cm')) +
annotation_logticks(sides = "b") +
theme_bw() +
facet_wrap( . ~ position,ncol=4) +
labs(x="Carbon Content Distribution (pgC)",
y= "Depth (m)")
ggsave("biomass_distribution.png", path = "./plots",height=10,width=8)
## Plot all pop distributions with height allow abundance comparisons across population
PSD_all %>%
group_by(position,depth) %>%
ggplot() +
ggridges::geom_density_ridges(aes(x = Qc, y = -depth, height = abundance_per_bin, fill =pop, group = interaction(depth,pop)), stat="identity", color="darkgrey", alpha=0.55,size=.15,panel_scaling=FALSE) + # panel_scaling=TRUE relative scaling is calculated separately for each panel. panel_scaling=FALSE, relative scaling is calculated globally
scale_x_continuous(trans = "log10") +
scale_fill_manual(name = 'Population', values = group_colors, breaks = c("bacteria",'prochloro','synecho',"picoeuk"), labels = c("Bacteria",'Pro','Syn',"Picoeuk")) +
theme(legend.key.size = unit(.35, 'cm')) +
annotation_logticks(sides = "b") +
theme_bw() +
facet_wrap( . ~ position,ncol=4) +
labs(x="Carbon Content Distribution (pgC)",
y= "Depth (m)")
ggsave("abundance_distribution.png", path = "./plots",height=10,width=8)
## Create individual PSDs for each population (distribution heights not comparable across populations)
PSD_wide <- PSD_all %>%
pivot_wider(names_from = pop, values_from = c("abundance_per_bin","biomass_per_bin"),values_fill=0) #issue is with cell_diameter column
PSD_wide[1:3,]
## Plot individual population PSDs (distribution heights not comparable across populations)
# Plot only to see the the distributions of each population, not quantitive or comparable across populations and panels
PSD_wide %>%
group_by(position,depth) %>%
ggplot() +
ggridges::geom_density_ridges2(aes(x = Qc, y = -depth, height = abundance_per_bin_bacteria, fill = "bacteria", group = depth), stat="identity", color="darkgrey", alpha=0.4,size=.25,panel_scaling=TRUE) + # panel_scaling=TRUE relative scaling is calculated separately for each panel. panel_scaling=FALSE, relative scaling is calculated globally
ggridges::geom_density_ridges2(aes(x = Qc, y = -depth, height = abundance_per_bin_prochloro, fill ="prochloro", group = depth), stat="identity", color="darkgrey", alpha=0.55,size=.25,panel_scaling=TRUE) + # panel_scaling=TRUE relative scaling is calculated separately for each panel. panel_scaling=FALSE, relative scaling is calculated globally
ggridges::geom_density_ridges2(aes(x = Qc, y = -depth, height = abundance_per_bin_synecho, fill="synecho", group = depth), stat="identity", color="darkgrey", alpha=0.55,size=.25,panel_scaling=TRUE) + # panel_scaling=TRUE relative scaling is calculated separately for each panel. panel_scaling=FALSE, relative scaling is calculated globally
ggridges::geom_density_ridges2(aes(x = Qc, y = -depth, height = abundance_per_bin_picoeuk, fill='picoeuk', group = depth), stat="identity", color="darkgrey", alpha=0.55,size=.25,panel_scaling=TRUE) + # panel_scaling=TRUE relative scaling is calculated separately for each panel. panel_scaling=FALSE, relative scaling is calculated globally
scale_x_continuous(trans = "log10",breaks = c(.01,.1,1,1,10), minor_breaks = c(.005,0.05,.5,5)) +
scale_fill_manual(name = 'Population', values = group_colors, breaks = c("bacteria",'prochloro','synecho',"picoeuk"), labels = c("Bacteria",'Pro','Syn',"Picoeuk")) +
theme(legend.key.size = unit(.35, 'cm')) +
annotation_logticks(sides = "b") +
theme_bw() +
facet_wrap( . ~ position,ncol=4) +
labs(x="Carbon Content Distribution (pgC)",
y= "Depth (m)")
ggsave("individual_abundance_distribution.png", path = "./plots",height=10,width=8)