Chapter 9 More than two groups
#::::::::::::::::::::::::::::::::::::::::::::::::: # Pairwise comparisons: Specify the comparisons you want my_comparisons <- list( c(“0.5”, “1”), c(“1”, “2”), c(“0.5”, “2”) ) ggboxplot(ToothGrowth, x = “dose”, y = “len”, color = “dose”, palette = “npg”)+ # Add pairwise comparisons p-value stat_compare_means(comparisons = my_comparisons, label.y = c(29, 35, 40))+ stat_compare_means(label.y = 45)
allsites_filtered <- All_sites %>% mutate(hc = log(height)) %>%
dplyr::filter(height > 0 & hr %in% c(1:24)) %>%
dplyr::filter(temp > -20) %>% as.data.frame()
my_comparisons <- list( c(0.3, 0.6) ,c(0.6, 0.9),c(0.9, 1.2),c(0.3, 1.2))
ggboxplot(allsites_filtered, x = "height", y = "temp",
palette = c("#00AFBB","#E7B800"),
add = "boxplot", add.params = list(fill = "white"))+
stat_compare_means(comparisons = my_comparisons) + # Add significance levels
stat_compare_means(label.y = 50) +
labs(title="Temperature between open and dense canopies (Hourly)",x="", y="Temperature(°C)", tag="", colour = "")
density plots
allsites_filtered_ridge <- All_sites %>% mutate(hc = log(height), hfac = as.factor(height)) %>%
dplyr::filter(height > 0 & hr %in% c(1:24)) %>%
dplyr::filter(temp > -20) %>% as.data.frame()
ggdensity(allsites_filtered_ridge, x = "temp",
add = "mean", rug = TRUE,
color = "canopy", palette = c("#00AFBB", "#E7B800")) +
theme_minimal(base_size=24) + labs(x=" Temperature (°C)", y="Density",color="Canopy")
ggsave("chap1_buffer_gaps_density.png",dpi=300, dev='png', height=8, width=8, units="in")
by height across all elevations
ggdensity(allsites_filtered_ridge, x = "temp",
add = "mean", rug = TRUE,facet.by = "height",
color = "canopy", palette = c("#00AFBB", "#E7B800")) +
theme_minimal(base_size=24) + labs(x=" Temperature (°C)", y="Density",color="Canopy")
ggsave("chap1_buffer_gaps_density_heights.png",dpi=300, dev='png', height=8, width=8, units="in")
by elevation
by height across all elevations, by hour
ggdensity(allsites_filtered_ridge, x = "temp",
add = "mean", rug = TRUE,facet.by = "hr",
color = "canopy", palette = c("#00AFBB", "#E7B800")) +
theme_minimal(base_size=24) + labs(x="Temperature (°C)", y="Density",color="Canopy")
ggsave("chap1_buffer_gaps_density_hr.png",dpi=300, dev='png', height=8, width=12, units="in")
by canopy across all the hours
allsites_filtered_ridge %>% group_by(canopy,hr) %>%
dplyr::summarise(mt= mean(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="Canopy",subtitle = "", x=" Time (hour)", y="Mean Temperature (°C)") + theme_minimal(base_size=18) +theme(legend.position = "bottom")
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
ggsave("chap1_bufferhrs_redo.png",dpi=300, dev='png', height=8, width=12, units="in")
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
library(ggpubr)
allsites_filtered_ridge %>% group_by(canopy,hr) %>%
dplyr::summarise(mt= mean(temp)) %>% ggboxplot(x= "canopy", y="mt", color = "canopy",
add="jitter", error.plot = "errorbar",
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Mean Temperature (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
temp1_hyp1 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
dplyr::summarise(mt= mean(temp)) %>% ggboxplot(x= "canopy", y="mt", color = "canopy",
add="jitter", error.plot = "errorbar",
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Mean Temperature (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
ggsave("chap1_bufferhrs_redo_mt.png",dpi=300, dev='png', height=8, width=12, units="in")
Mean temperature at different eight
library(ggpubr)
allsites_filtered_ridge %>% group_by(height,canopy,hr) %>%
dplyr::summarise(mt= mean(temp)) %>% ggboxplot(x= "canopy", y="mt", color = "canopy",
add="jitter", error.plot = "errorbar", facet.by = "height", short.panel.labs = FALSE,
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Mean Temperature (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
temp2_hyp1 <- allsites_filtered_ridge %>% group_by(height,canopy,hr) %>%
dplyr::summarise(mt= mean(temp)) %>% ggboxplot(x= "canopy", y="mt", color = "canopy",
add="jitter", error.plot = "errorbar", facet.by = "height", short.panel.labs = FALSE,
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Mean Temperature (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
ggsave("chap1_bufferhrs_redo_mt_height.png",dpi=300, dev='png', height=8, width=12, units="in")
library(ggpubr)
allsites_filtered_ridge %>% group_by(canopy,day) %>%
dplyr::summarise(mt= mean(temp),dv=max(temp)-min(temp)) %>% ggboxplot(x= "canopy", y="dv", color = "canopy",
add="jitter", error.plot = "errorbar",
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Diurnal variation (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
dv1_hyp1 <- allsites_filtered_ridge %>% group_by(canopy,day) %>%
dplyr::summarise(mt= mean(temp),dv=max(temp)-min(temp)) %>% ggboxplot(x= "canopy", y="dv", color = "canopy",
add="jitter", error.plot = "errorbar",
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Diurnal variation (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
ggsave("chap1_bufferhrs_redo_mt_diurnal.png",dpi=300, dev='png', height=8, width=12, units="in")
library(ggpubr)
allsites_filtered_ridge %>% group_by(canopy,height,day) %>%
dplyr::summarise(mt= mean(temp),dv=max(temp)-min(temp)) %>% ggboxplot(x= "canopy", y="dv", color = "canopy",
add="jitter", error.plot = "errorbar", facet.by = "height", short.panel.labs = FALSE,
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Diurnal variation (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
dv2_hyp1 <- allsites_filtered_ridge %>% group_by(canopy,height,day) %>%
dplyr::summarise(mt= mean(temp),dv=max(temp)-min(temp)) %>% ggboxplot(x= "canopy", y="dv", color = "canopy",
add="jitter", error.plot = "errorbar", facet.by = "height", short.panel.labs = FALSE,
palette = c("#00AFBB", "#E7B800")) + labs(subtitle = "", x="", y="Diurnal variation (°C)") +
stat_compare_means( aes(label = ..p.signif..),
label.x = 1.5, label.y = 15) +
ylim(0,15)+
scale_x_discrete(labels=c("Dense canopy", "Gaps")) +
theme_minimal(base_size=24) +theme(legend.position = "bottom") +
theme(legend.position = "")
ggsave("chap1_bufferhrs_redo_mt_diurnal_height.png",dpi=300, dev='png', height=8, width=12, units="in")
library(patchwork)
##
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
##
## align_plots
## The following object is masked from 'package:raster':
##
## area
(temp2_hyp1 + temp1_hyp1) /(dv2_hyp1 + dv1_hyp1)
ggsave("chap1_buffer_gaps_hyp1_mp.png",dpi=300, dev='png', height=12, width=14, units="in")
Combine the plot
ggdensity(allsites_elevation_sigf, x = "dv",
add = "mean", rug = TRUE,facet.by = "elevation",
color = "canopy", palette = c("#00AFBB", "#E7B800")) +
theme_minimal(base_size=24) + labs(x=" Diel Temperature (°C)", y="Density",color="Canopy")
ggsave("chap1_buffer_gaps_density_elevation_dv.png",dpi=300, dev='png', height=8, width=8, units="in")
by height across all elevations, by hour
point6 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.6) %>%
dplyr::summarise(mt= mean(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.6m", x=" Time (hour)", y="Mean Temperature (°C)") + theme_minimal(base_size=18) +theme(legend.position = "")
point3 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.3) %>%
dplyr::summarise(mt= mean(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.3m",x=" Time (hour)", y="Mean Temperature (°C)")+
theme_minimal(base_size=18) +theme(legend.position = "")
point9 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.9) %>%
dplyr::summarise(mt= mean(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.9m",x=" Time (hour)", y="Min Temperature (°C)") +
theme_minimal(base_size=18) +theme(legend.position = "bottom",legend.direction = "horizontal")
onepoint2 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==1.2) %>%
dplyr::summarise(mt= mean(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "1.2m",x=" Time (hour)", y="Min Temperature (°C)") +
theme_minimal(base_size=18) +theme(legend.position = "bottom",legend.direction = "horizontal")
library(patchwork)
(point3 + point6) / (point9 + onepoint2)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
ggsave("chap1_buffer_gaps_hr_by_height_redo.png",dpi=300, dev='png', height=10, width=12, units="in")
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
by height across all elevations, by hour min
point6 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.6) %>%
dplyr::summarise(mt= min(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.6m", x=" Time (hour)", y="Min Temperature (°C)") + theme_minimal(base_size=18) +theme(legend.position = "")
point3 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.3) %>%
dplyr::summarise(mt= min(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.3m",x=" Time (hour)", y="Min Temperature (°C)")+
theme_minimal(base_size=18) +theme(legend.position = "")
point9 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.9) %>%
dplyr::summarise(mt= min(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.9m",x=" Time (hour)", y="Min Temperature (°C)") +
theme_minimal(base_size=18) +theme(legend.position = "bottom",legend.direction = "horizontal")
onepoint2 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==1.2) %>%
dplyr::summarise(mt= min(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "1.2m",x=" Time (hour)", y="Min Temperature (°C)") +
theme_minimal(base_size=18) +theme(legend.position = "bottom",legend.direction = "horizontal")
library(patchwork)
(point3 + point6) / (point9 + onepoint2)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
ggsave("chap1_buffer_gaps_hr_by_height_min_redo.png",dpi=300, dev='png', height=10, width=12, units="in")
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
max
point6 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.6) %>%
dplyr::summarise(mt= max(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.6m", x=" Time (hour)", y="Max Temperature (°C)") + theme_minimal(base_size=18) +theme(legend.position = "")
point3 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.3) %>%
dplyr::summarise(mt= max(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.3m",x=" Time (hour)", y="Max Temperature (°C)")+
theme_minimal(base_size=18) +theme(legend.position = "")
point9 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==0.9) %>%
dplyr::summarise(mt= max(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "0.9m",x=" Time (hour)", y="Max Temperature (°C)") +
theme_minimal(base_size=18) +theme(legend.position = "bottom",legend.direction = "horizontal")
onepoint2 <- allsites_filtered_ridge %>% group_by(canopy,hr) %>%
filter(height==1.2) %>%
dplyr::summarise(mt= max(temp)) %>% ggdotplot( "hr", "mt",
fill = "canopy",
palette = c("#00AFBB", "#E7B800")) + labs(fill="",subtitle = "1.2m",x=" Time (hour)", y="Max Temperature (°C)") +
theme_minimal(base_size=18) +theme(legend.position = "bottom",legend.direction = "horizontal")
library(patchwork)
(point3 + point6) / (point9 + onepoint2)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
ggsave("chap1_buffer_gaps_hr_by_height_max_redo.png",dpi=300, dev='png', height=10, width=12, units="in")
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
first hump is early mornings, where the open canopy is warming
ggdensity(allsites_elevation_sigf, x = "dv",
add = "mean", rug = TRUE,facet.by = "elevation",
color = "canopy", palette = c("#00AFBB", "#E7B800")) +
theme_minimal(base_size=24) + labs(x=" Diel Temperature (°C)", y="Density",color="Canopy")
ggsave("chap1_buffer_gaps_density_elevation_dv.png",dpi=300, dev='png', height=8, width=8, units="in")
ggdensity(allsites_elevation_sigf, x = "mean_temp",
add = "mean", rug = TRUE,facet.by = "elevation",
color = "canopy", palette = c("#00AFBB", "#E7B800")) +
theme_minimal(base_size=24)
ggsave("chap1_buffer_gaps_density_elevation_mean_temp.png",dpi=300, dev='png', height=8, width=8, units="in")
All_site_withelevationheight <- All_site_withelevation %>% mutate(hcf= factor(height))
ggdensity(All_site_withelevationheight, x = "temp",
add = "mean", rug = TRUE,facet.by = "elevation",
color = "hcf",fill="hcf") +
theme_minimal(base_size=24)
ggsave("chap1_buffer_gaps_density_elevation_height_temp.png",dpi=300, dev='png', height=8, width=8, units="in")
impo resut - early morning 1.2 is much warmer , day time ground is warmer
All_site_withelevationheight <- All_site_withelevation %>% mutate(hcf= factor(height))
ap <- ggdensity(All_site_withelevationheight, x = "temp",
add = "mean", rug = TRUE,
color = "hcf") +
theme_minimal(base_size=24)
ap + labs(x=" Temperature (°C)", y="Density",color="Height (m)")
ggsave("chap1_buffer_gaps_density_height_profile.png",dpi=300, dev='png', height=8, width=8, units="in")
All_site_withelevationheight <- All_site_withelevation %>% mutate(hcf= factor(height))
ap <- ggdensity(All_site_withelevationheight, x = "temp",
add = "mean", rug = TRUE,
color = "hcf") +
theme_minimal(base_size=24)
ap + facet_grid(elevation ~ hcf, scales='free')
ggsave("chap1_buffer_gaps_density_height_elevation_profile.png",dpi=300, dev='png', height=8, width=8, units="in")
All_site_withelevationheight <- All_site_withelevation %>% mutate(hcf= factor(height))
ap <- ggdensity(All_site_withelevationheight,x = "temp",
color = "canopy", rug = TRUE) +
theme_minimal(base_size=24)
ap + facet_grid(elevation ~ hcf, scales='free') + labs(x=" Temperature (°C)", y="Density",color="Canopy")
ggsave("chap1_buffer_gaps_density_height_elevation_profile.png",dpi=300, dev='png', height=8, width=12, units="in")