-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR code.R
62 lines (43 loc) · 1.97 KB
/
R code.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
# MODELING AVALANCHE PROTECTION IN FORESTS
# Author: Francesc Molné Correig
# Date: 2020
# Description: The code loads the results from the model and plots
# Load packages:
library(dplyr)
library(reshape2)
library(chron)
library(ggplot2)
library(GGally)
library(car)
library(corrplot)
library(lattice)
# Load results file and check:
file_results <- file.path("results.csv") # Call file directory. The results file has to be located at the same directory than the code
results <- read.table(file_results, # Read the results data frame, and specify
header = TRUE,
sep = ";",
dec = ",")
head(results) # Verify the correct loading by checking the first rows of the results dataframe
# Adapt the dataframe (convert into a molten dataframe):
results_melt1 <- melt(results,
id.vars=c("Frame",
"Time",
"Forest_structure",
"Snow_type")
)
head(results_melt1) # Verify the transformation
results_melt1$Forest_structure <- factor(results_melt1$Forest_structure,
levels = c ("No forest",
"Ordered forest",
"Random forest",
"Clustered forest")
)
# Plot the avalanche response variables as a function of time (for every snow type):
plot_results1 <- ggplot(results_melt1)
+ facet_grid(variable ~ Snow_type,
scales = "free_y") # panels created out of these variables
+ geom_line(aes(Time,
value,
color = Forest_structure)
)
print(plot_results1) # view the plot