-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHAMAC-E5-LandUsePlot.R
More file actions
173 lines (147 loc) · 5.98 KB
/
Copy pathHAMAC-E5-LandUsePlot.R
File metadata and controls
173 lines (147 loc) · 5.98 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
###################
## HAMAC Routine ##
###################
## Landscape unit plots
## Arthur SCRIBAN - AVRIL 2024
### Libraries
library(ggplot2)
### Paths
inDir <- "./1_IntermeData"
graphDir <- "./4_VisualOutputs"
### Functions
### Execution
OcuSolsLegende <- read.csv2(paste0(inDir, "/OcuSolsClasses.csv"))
# Labels pour les différentes variables
OcuSolsLegende$SES <- factor(OcuSolsLegende$SES,
levels = c("SSf", "SSc", "SP"),
labels = c("Cold dry season", "Warm dry season", "Rainy season"))
OcuSolsLegende$DAYTM <- factor(OcuSolsLegende$DAYTM,
labels = c("Nighttime", "Daytime"))
OcuSolsLegende$TRA <- factor(OcuSolsLegende$TRA,
labels = c("Resident herds", "Transhumant herds"))
OcuSolsLegende$VIT <- factor(OcuSolsLegende$VIT,
labels = c("Resting", "Foraging", "Travelling"))
OcuSolsLegende$Legende.courte <- factor(OcuSolsLegende$Legende.finale, labels = c(
# Arbres Bas fonds Bâti Champs de brousse
# Champs de cases Cours d'eau Jachère Jardins
# Mares Parcours Routes Sol nu
# "Trees", "Lowlands", "Dwellings", "Bushfields",
# "Homefields*", "Rivers", "Fallows*", "Gardens*",
# "Ponds*", "Rangelands", "Roads*", "Naked ground"))
"Cropland trees*", "Lowlands", "Homefields*", "Bushfields",
"Homefields*", "Lowlands", "Fallows*", "Other",
"Lowlands", "Rangelands", "Other", "Bushfields"))
## Explo
# [OcuSolsLegende$TRA == 'Resident herds',]
ggplot(OcuSolsLegende,
aes(x = factor(VIT, labels = c("RST", "FRG", "TVL")),
fill = factor(Legende.courte, levels = c(
"Other", "Lowlands", "Rangelands", "Fallows*", "Bushfields", "Homefields*")))) +
facet_grid(
TRA ~
SES +
factor(DAYTM, levels = c("Daytime", "Nighttime"), labels = c("DT", "NT")),
scales = "free_y"
) +
geom_bar(stat = "count") +
scale_y_continuous(
name = "Amount of observations",
labels = function(x) paste0(x / 1000, "k"),
# sec.axis = sec_axis(~ . * 100, name = "Percentage of observations")
) +
scale_fill_brewer(palette = "BrBG") +
theme_minimal() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
) +
labs(x = "Activity state",
y = "Amount of observations",
fill = "Land use")
### Alternative avec des pourcentages
OcuSolsLegendePercent <- OcuSolsLegende %>%
group_by(TRA, SES, DAYTM, VIT, Legende.courte) %>%
summarise(count = n(), .groups = 'drop') %>%
group_by(TRA, SES, DAYTM) %>%
mutate(percentage = count / sum(count))
ggplot(OcuSolsLegendePercent,
aes(x = factor(VIT, labels = c("RST", "FRG", "TVL")), y = percentage,
fill = factor(Legende.courte, levels = c(
"Other", "Rangelands", "Lowlands", "Cropland trees*",
"Fallows*", "Bushfields", "Homefields*")))) +
facet_grid(
SES ~ TRA + factor(DAYTM, levels = c("Daytime", "Nighttime")),
scales = "free_y"
) +
geom_bar(stat = "identity", position = "stack") +
scale_fill_manual(values = c(
"#666666", "#018571", "#80cdc1", "#f6e8c3", "#dfc27d", "#bf812d", "#8c510a"
)) +
# scale_fill_brewer(palette = "BrBG", direction=-1) +
theme_minimal() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
labs(x = "Activity state",
y = "Proportions of observations in each state per case",
fill = "Land use")
## Figure globale
ggplot(OcuSolsLegende, aes(x = SES, fill = Legende.courte)) +
facet_grid(VIT ~ TRA) + # Ajouter factor et labels
geom_bar(position = "fill", stat = "count") +
scale_y_continuous(labels = scales::percent_format()) +
labs(title = "Proportion de paysage occupé par état des troupeaux et par saison",
x = "Season",
y = "Observations proportion",
fill = "Occupation du sol")
## Histogramme des distances parcourues la nuit pour les transhumants par éleveur
ggplot(OcuSolsLegende, aes(x =
SES,
# factor(MON, labels = c(
# "Jan", "Feb", "Mar", "Apr", "May", "Jun",
# "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")),
y = step,# group = ID,
fill = VIT)) +
facet_grid(DAYTM ~ .) +
geom_col() +
# scale_y_continuous(labels = scales::percent_format()) + # Pour stacker ? 100%
labs(title = "Distances observées parcourues par mois",
x = "Month",
y = "Distance (km)",
fill = "Etat") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
# Fertility transfers
PerSESTRA <- OcuSolsLegendePercent %>%
group_by(TRA, VIT, SES, Legende.courte, DAYTM) %>%
summarise(total_count = sum(count), .groups = 'drop')
CondensPerSESTRA <- PerSESTRA[PerSESTRA$TRA == "Resident herds",]
CondensPerSESTRA <- CondensPerSESTRA[CondensPerSESTRA$SES != "Rainy season",]
CondensPerSESTRA <- CondensPerSESTRA %>%
group_by(DAYTM, Legende.courte) %>%
summarise(total_count = sum(total_count), .groups = 'drop')
ggplot(OcuSolsLegendePercent,
aes(x = DAYTM, y = percentage,
fill = factor(Legende.courte, levels = c(
"Other", "Rangelands", "Lowlands", "Cropland trees*",
"Fallows*", "Bushfields", "Homefields*")))) +
facet_grid(
SES ~ TRA,
scales = "free_y"
) +
geom_bar(stat = "identity", position = "stack") +
scale_fill_manual(values = c(
"#666666", "#018571", "#80cdc1", "#f6e8c3", "#dfc27d", "#bf812d", "#8c510a"
)) +
# scale_fill_brewer(palette = "BrBG", direction=-1) +
theme_minimal() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
labs(x = "Activity state",
y = "Proportions of observations in each state per case",
fill = "Land use")
#### Intermediate data save