Commit 3a946e7e authored by Boulangeat Isabelle's avatar Boulangeat Isabelle
Browse files

prepa reu 15-10

parent e2f8c33c
No preview for this file type
No preview for this file type
install.packages("remotes")
remotes::install_github("jalvesaq/colorout")
??inout
install.packages("splancs")
?reclass
?breaks
?break
?addPolygons
library(leaflet)
?addPolygons
?colorBins
?colorBin
?addLegend
library(sf)
install.packages("sf")
library(sf)
?sf_interset
?sf_intersect
?intersect
?st_intersection
install.packages("rgeos")
library(rgeos)
?gIntersect
?gOverlap
?gOverlaps
?pairs
install.packages("queyras")
shiny::runApp('PROJETS/SOCBIO_Yves/ASONB/gitlab-folder/exploHumanImpactData')
?write.csv
library(FD)
?divc
install.pacakges("rgdal")
install.packages("rgdal")
library(rgdal)
install.packages("adespatial")
library(adespatial)
library(adespatial)
library(sf)
setwd("~/Documents/PROJETS/HISTFUNC/H3")
library(remake)
remake::make("herbivores")
remake::make("herbivores")
?pairs
?extract
install.packages("tidyverse")
shiny::runApp('~/Documents/PROJETS/SOCBIO_Yves/ASONB/gitlab-folder/exploHumanImpactData')
install.packages("PostgreSQL")
install.packages("RPostgres")
install.packages("rpostgis")
install.packages("RPostgreSQL")
plotmo(mod, ylim = NA)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900", "frost.gdd300",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
library(plotmo)
plotmo(mod, ylim = NA)
str(releves_all$ref_typoveg)
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA")),c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~ ., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900", "frost.gdd300",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA")),c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
library(plotmo)
plotmo(mod, ylim = NA)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900", "frost.gdd300",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900", "ref_typoveg")
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA")),c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900", "frost_severe.gdd300", "frost_severe.gdd600",
"frost_severe.gdd900", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900", "ref_typoveg" )
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
head(releves_all)
source('~/Documents/PROJETS/ZAA/AS/git_as_biomass/workflow2_climate.r', encoding = 'UTF-8')
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900", "frost_severe.gdd300", "frost_severe.gdd600",
"frost_severe.gdd900", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
sapply(list.files("R_fct"), function(x)source(paste0("R_fct/",x)))
setwd("~/Documents/PROJETS/ZAA/AS/git_as_biomass")
sapply(list.files("R_fct"), function(x)source(paste0("R_fct/",x)))
require(RPostgreSQL)
data = readRDS("data.rds")
head(data$sites)
dat_h_veg = merge(data$h, data$sites[,c("id_site", "ref_typoveg")], by.x = "ref_site", by.y ="id_site")
str(dat_h_veg)
summary(dat_h_veg$hmean)
sites_all = readRDS("sites_all.rds")
data_h = readRDS("data_h.rds")
head(data_h)
releves = unique(merge(data_h, sites_all, by.x="ref_site", by.y = "id_site"))
releves$year= unlist(lapply(releves$date_releve, substr, start = 1,stop=4))
# require(lubridate)
# releves$day_number = as.integer(unlist(lapply(releves$date_releve, function(x){
# time_length(interval(start = ymd(paste0(substr(x, 1, 4),"-08-01")), end = x), unit = "days")
# })))
# summary(releves$day_number)
head(releves)
path_data_allslopes = "/Volumes/infogeo/Meteo_France/SAFRAN_montagne-Crocus_2020/alp_allslopes"
#path_data_allslopes = "/Volumes/ISA-RESEARCH/alp_allslopes"
# nc = nc_open(paste0(path_data_allslopes, "/reanalysis/pro/PRO_",as.character(year),"080106_",as.character(year+1),"080106.nc"))
# ncatt_get( nc, "TALB_ISBA")
library(dplyr)
# library(reshape)
library(tidyr)
library(ggplot2)
dat_long <- dat_h_veg %>%
select(hmean, hmad, ref_typoveg) %>%
drop_na() %>%
group_by(ref_typoveg) %>%
summarize(hauteur=mean(hmean), var_inter=mad(hmean), var_intra = mean(hmad)) %>%
gather(stat, value, hauteur:var_intra)
ggplot(dat_long, aes(fill=stat, x=ref_typoveg, y=value)) +
geom_bar(position = "dodge", stat = "identity") +
facet_wrap(~stat, ncol = 1, scales = "free")
head(dat_long)
head(dat_h_veg)
pl <- ggplot(dat_h_veg, aes(x = date_releve, y = hmean)) +
geom_line(aes(color = ref_site), show.legend = FALSE) +
facet_wrap(~ref_typoveg)
pl + theme(legend.position = "none")
head(dat_h_veg)
ggplot(dat_h_veg, aes(x = ref_typoveg, y = hmean)) +
geom_boxplot(stat = "identidy")
ggplot(dat_h_veg, aes(x = ref_typoveg, y = hmean)) +
geom_boxplot(stat = "identity")
ggplot(dat_h_veg, aes(x = ref_typoveg, y = hmean)) +
geom_boxplot()
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean), y = hmean)) +
geom_boxplot()
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean, na.rm=TRUE), y = hmean)) +
geom_boxplot()
summary(dat_h_veg)
dat_h_veg[which(is.na(dat_h_veg$hmad)),]
dat_h_veg[which(is.na(dat_h_veg$hmad)),"ref_site"]
unique(dat_h_veg[which(is.na(dat_h_veg$hmad)),"ref_site"])
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean, na.rm=TRUE), y = hmean)) +
geom_boxplot() +
labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation",
labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation")
labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation")
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean, na.rm=TRUE), y = hmean)) +
# test = releves %>% select(releve, NoP, year, date_releve) %>% filter(year == "2017")
# test = test[1:6,]
#
# res = calc_meteo_variables(path_data_allslopes, as.numeric(test$year[1]), test$date_releve, test$NoP, c(30,60))
# dim(res)
# dimnames(res)[[1]] = test$releve
dim(releves)
releves2 = releves[-which(releves$year>2018),]
dim(releves2)
list_outputs <- lapply(unique(releves2$year), function(y){
print(y)
# y=2017
selected = releves2 %>% dplyr::select(releve, NoP, year, date_releve) %>% filter(year == y)
res = calc_meteo_variables(path_data_allslopes, as.numeric(selected$year[1]), selected$date_releve, selected$NoP, c(300, 600,900), tbase=0)
res
})
names_releves_list = lapply(unique(releves2$year), function(y){
selected = releves2 %>% dplyr::select(releve, NoP, year, date_releve) %>% filter(year == y)
selected$releve
})
NoP_year_list = lapply(unique(releves2$year), function(y){
selected = releves2 %>% dplyr::select(releve, NoP, year, date_releve) %>% filter(year == y)
paste0(selected$NoP, "_", selected$year)
})
# res = list(var_gdd_treshold = output, last_snow = LSD, snowfree_time = time_after_nosnow, cumGDD0 = cumGDD0, cumGDD60d = cumGDD60d)
# output = array(data = NA, dim = list(length(unique(NoPs)),8, length(periods)), dimnames = list(paste0(unique(NoPs), "_", year), c("gddspeed", "snowdays", "frost", "frost_severe", "radiations", "albedo", "rainfall", "hydro"), periods))
length(list_outputs)
length(list_outputs[[1]])
dim(list_outputs[[1]][[1]])
length(list_outputs[[1]][[2]])
list_opt = lapply(list_outputs, function(x)x[[1]])
length(list_opt)
dim(list_opt[[1]])
last_snow_day = unlist(lapply(list_outputs, function(x)x[[2]]))
length(last_snow_day)
df_rel = data.frame(snowfree_time = unlist(lapply(list_outputs, function(x)x[[3]])), cumgdd0 = unlist(lapply(list_outputs, function(x)x[[4]])), cumgdd60d = unlist(lapply(list_outputs, function(x)x[[5]])))
rownames(df_rel) = unlist(names_releves_list)
final_array = abind(list_opt, along = 1)
dim(final_array)
head(final_array)
# build output (array to df)
df_list = lapply(1:3, function(x){
df <- as.data.frame.table(cbind(final_array[,,x], last_snow_day))
df$gdd = c("gdd300", "gdd600", "gdd900")[x]
colnames(df) = c("NoP_year", "meteo_variable", "value", "gdd_threshold")
df
})
df_flat = do.call(rbind.data.frame, df_list)
head(df_flat)
tail(df_flat)
df_gdd = df_flat %>% unite("meteo", meteo_variable, gdd_threshold, sep = ".") %>% spread(meteo, value)
head(df_gdd)
## combine data.frame(x,y)
head(df_rel)
df_rel$NoP_year = unlist(NoP_year_list)
df_rel$releve = rownames(df_rel)
df_final = merge(df_rel, df_gdd, by = "NoP_year")
head(df_final)
releves_all = merge(releves, df_final, all=FALSE)
head(releves_all[order(releves_all$releve),])
saveRDS("releves_all", file = "releves_all.rds")
########
library(raster)
mnt25m <- raster("/Volumes/ISA-RESEARCH/_DATA/zaa_mnt/mntAlpes_25m.tif")
aspect_alps <- raster("/Volumes/ISA-RESEARCH/_DATA/zaa_CHABLI_DB/_spatialManips/aspect_trigo_alps.tif")
slope_alps <- raster("/Volumes/ISA-RESEARCH/_DATA/zaa_CHABLI_DB/_spatialManips/slopeAlps.tif")
lf = raster("/Volumes/ISA-RESEARCH/_DATA/zaa_landform/landform_tpi_saga_juill2020.tif")
projection(mnt25m)==projection(lf)
projection(sites_all)
plot(mnt25m)
points(sites_all)
sites_all$alti = extract(mnt25m, sites_all)
sites_all$slope = extract(slope_alps, sites_all)
sites_all$lf = extract(lf, sites_all)
library(shadow)
sites_all$northing = cos(deg2rad(extract(aspect_alps, sites_all)))
sites_all$easting = sin(deg2rad(extract(aspect_alps, sites_all)))
sites_all$aspect = extract(aspect_alps, sites_all)
summary(sites_all)
head(sites_all)
reltot = merge(sites_all@data[,c("id_site", "alti", "slope", "lf", "northing", "easting")], releves_all, by.x = "id_site", by.y="ref_site")
head(reltot)
saveRDS(reltot, file = "releves_all_plus.rds")
saveRDS(sites_all, file = "sites_all_plus.rds")
# ###### analyse sites - type - topo
# library(ggplot2)
#
# ggplot(sites_all@data, aes(x = reorder(ref_typoveg, alti, na.rm=TRUE), y = alti)) +
# geom_boxplot() +
# labs(y="alti", x="Type vegetation")
#
#
# ggplot(sites_all@data, aes(x = reorder(ref_typoveg, slope, na.rm=TRUE), y = slope)) +
# geom_boxplot() +
# labs(y="slope", x="Type vegetation")
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
ggplot(releves_all, aes(x = reorder(ref_typoveg, cumgdd0, na.rm=TRUE), y = cumgdd0)) +
geom_boxplot() +
labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation")
head(data)
head(data$h)
head(data$sites)
tail(data$h)
summary(data$h$hmean)
data$h$ref_releve[which(is.na(data$h$hmean))]
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hsd, na.rm=TRUE), y = hsd)) +
labs(y="cum GDD 0degC", x="Type vegetation")
ggplot(releves_all, aes(x = reorder(ref_typoveg, last_snow_day.gdd300, na.rm=TRUE), y = last_snow_day.gdd300)) +
geom_boxplot() +
labs(y="Hétérogénéité", x="Type vegetation")
summary(data_h_veg$ref_typoveg)
summary(dat_h_veg$ref_typoveg)
table(dat_h_veg$ref_typoveg)
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hsd, na.rm=TRUE), y = hsd)) +
labs(y="LSD", x="Type vegetation")
ggplot(releves_all, aes(x = reorder(ref_typoveg, cumgdd0, na.rm=TRUE), y = cumgdd0)) +
geom_boxplot() +
labs(y="Variation intra de hauteur", x="Type vegetation")
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hsd, na.rm=TRUE), y = hsd/hmean)) +
labs(y="cum GDD 0degC", x="Type vegetation")
releves_all$date600 = releves_all$last_snow_day.gdd300 + releves_all$gddspeed.gdd600
ggplot(releves_all, aes(x = reorder(ref_typoveg, date600, na.rm=TRUE), y = date600)) +
geom_boxplot() +
labs(y="Variation intra de hauteur", x="Type vegetation")
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad/hmean, na.rm=TRUE), y = hsd)) +
labs(y="dateGDD600", x="Type vegetation")
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900", "ref_typoveg" )
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA")),c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~ ., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900", "ref_typoveg" )
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA")),c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~ ., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
str(releves_all)
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
ggplot(releves_all, aes(x = reorder(ref_typoveg, cumgdd60d, na.rm=TRUE), y = cumgdd60d)) +
geom_boxplot() +
labs(y="Variation intra de hauteur", x="Type vegetation")
ggplot(dat_h_veg, aes(x = hmad, y = hsd)) +
geom_points()
ggplot(dat_h_veg, aes(x = hmad, y = hsd)) +
geom_point()
ggplot(dat_h_veg, aes(x = date_releve, y = hsd)) +
geom_line(aes(color = ref_site), show.legend = FALSE) +
facet_wrap(~ref_typoveg)
ggplot(dat_h_veg, aes(x = date_releve, y = hmad)) +
geom_line(aes(color = ref_site), show.legend = FALSE) +
facet_wrap(~ref_typoveg)
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad, na.rm=TRUE), y = hmad)) +
labs(y="cum GDD 60d", x="Type vegetation")
ggplot(releves_all, aes(x = reorder(ref_typoveg, temperature.gdd300, na.rm=TRUE), y = temperature.gdd300)) +
geom_boxplot() +
labs(y="Variation intra de hauteur", x="Type vegetation")
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad/hmean, na.rm=TRUE), y = hmad/hmean)) +
labs(y="temperature moy", x="Type vegetation")
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900", "ref_typoveg" )
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~ ., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
releves_all = readRDS("releves_all_plus.rds")
library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
releves_all$date600 = releves_all$last_snow_day.gdd300 + releves_all$gddspeed.gdd600
ggplot(releves_all, aes(x = reorder(ref_typoveg, date600, na.rm=TRUE), y = date600)) +
geom_boxplot() +
labs(y="Variation intra de hauteur", x="Type vegetation")
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad/hmean, na.rm=TRUE), y = hmad/hmean)) +
labs(y="dateGDD600", x="Type vegetation")
ggplot(releves_all, aes(x = cumgdd0, y = hmean)) +
geom_point() +
geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) +
labs(y="Hauteur", x="GDD 0degree")
ggplot(releves_all, aes(x = gddspeed.gdd600, y = hmean)) +
geom_point() +
geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) +
labs(y="Hauteur", x="GDD.600")
## boxplot par milieu ##
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean, na.rm=TRUE), y = hmean)) +
geom_boxplot() +
labs(y="Variation intra de hauteur (stand. moy.)", x="Type vegetation")
head(dat_h_veg)
head(dat_h_veg)
dat_h_veg[which(dat_h_veg$ref_site=="BELRIV01"),]
sapply(dat_h_veg$ref_releve, function(x){
paste(strplit(x, "_")[-2])
})
sapply(dat_h_veg$ref_releve, function(x){
paste(strsplit(x, "_")[-2])
})
sapply(dat_h_veg$ref_releve, function(x){
paste(unlist(strsplit(x, "_")[-2]))
})
sapply(dat_h_veg$ref_releve, function(x){
paste(unlist(strsplit(x, "_"))[-2])
})
lapply(dat_h_veg$ref_releve, function(x){
paste(unlist(strsplit(x, "_"))[-2])
})
unlist(lapply(dat_h_veg$ref_releve, function(x){
paste(unlist(strsplit(x, "_"))[-2], sep="_")
}))
sapply(dat_h_veg$ref_releve, function(x){
paste(unlist(strsplit(x, "_"))[-2], sep="_")
})
x = dat_h_veg$ref_releve[1]
strsplit(x, "_")
strsplit(x, "_")[-2]
strsplit(x, "_")[[1]][-2]
sapply(dat_h_veg$ref_releve, function(x){
paste(strsplit(x, "_")[[1]][-2], sep="_")
})
lapply(dat_h_veg$ref_releve, function(x){
paste(strsplit(x, "_")[[1]][-2], sep="_")
})
x
strsplit(x, "_")[[1]][-2]
paste(strsplit(x, "_")[[1]][-2], sep="_")
paste(strsplit(x, "_")[[1]][-2], sep="_", collapse = TRUE)
x1 = strsplit(x, "_")[[1]][-2]
paste(x1, sep="_")
x1
paste(x1, collapse="_")
x1 =
paste(strsplit(x, "_")[[1]][-2], collapse="_")
x1 =
paste(strsplit(x, "_")[[1]][-2], collapse="_")
paste(strsplit(x, "_")[[1]][-2], collapse="_")
lapply(dat_h_veg$ref_releve, function(x){
paste(strsplit(x, "_")[[1]][-2], collapse="_")
})
dat_h_veg$releveL1L2 =
unlist(lapply(dat_h_veg$ref_releve, function(x){
paste(strsplit(x, "_")[[1]][-2], collapse="_")
}))
head(dat_h_veg)
data = readRDS("data.rds")
#==============================
## dataframe ##
#===============================
head(data$sites)
head(data$h)
dat_h_veg = merge(data$h, data$sites[,c("id_site", "ref_typoveg")], by.x = "ref_site", by.y ="id_site")
str(dat_h_veg)
labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation")
library(knitr)
# library(kableExtra)
knitr::opts_chunk$set(echo = TRUE)
# library(Jmisc)
library(tidyr)
sapply(list.files("R_fct"), function(x)source(paste0("R_fct/",x)))
data = readRDS("data.rds")
#==============================
## dataframe ##
#===============================
head(data$sites)
head(data$h)
## boxplot par milieu ##
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean, na.rm=TRUE), y = hmean)) +
geom_boxplot() +
labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation")
ggplot(dat_long, aes(fill=stat, x=ref_typoveg, y=value)) +
geom_bar(position = "dodge", stat = "identity") +
facet_wrap(~stat, ncol = 1, scales = "free")
library(knitr)
# library(kableExtra)
knitr::opts_chunk$set(echo = TRUE)
# library(Jmisc)
library(tidyr)
sapply(list.files("R_fct"), function(x)source(paste0("R_fct/",x)))
data = readRDS("data.rds")
#==============================
## dataframe ##
#===============================
head(data$sites)
head(data$h)
dat_h_veg = merge(data$h, data$sites[,c("id_site", "ref_typoveg")], by.x = "ref_site", by.y ="id_site")
str(dat_h_veg)
summary(dat_h_veg$hmean)
dat_h_veg = unique(merge(data$h, data$sites[,c("id_site", "ref_typoveg")], by.x = "ref_site", by.y ="id_site"))
length(unique(dat_h_veg$releve))
dim(dat_h_veg)
summary(dat_h_veg$hmean)
head(data$otable)
data$otable[which(is.na(data$otable$hauteur)),]
summary(dat_h_veg$hmean)
dat_long <- dat_h_veg %>%