J'ai une question technique pour vous s'il vous plait :
Code : Tout sélectionner
data_observation <- data.frame(
superficie_essence = c(
0, 0, 0, 0, 10,
10, 30, 30, 30, 45,
65, 65, 65, 80, 80,
80, 90, 95, 100
),
effort = c(
1, 1.5, 1, 3, 3, 4.5, 3, 1, 1, 3.5, 11,
10, 14.5, 14, 12, 3, 4, 6, 19
)
)
Ma fonction pour faire des barplots :
Code : Tout sélectionner
library(dplyr)
library(ggplot2)
library(scales)
barplot_effort_habitat <- function(data = NULL, habitat_type = NULL, Effort = NULL){
x <- enquo(habitat_type)
y <- enquo(Effort)
dataII <- data %>%
select(x = !!x, y = !!y) %>%
mutate(group = factor(case_when(
x == 0 ~ "[0]",
x > 0.0001 & x < 10.0001 ~ "]0-10]",
x > 10.0001 & x < 25.0001 ~ "]10-25]",
x > 25.0001 & x < 50.0001 ~ "]25-50]",
x > 50.0001 & x < 75.0001 ~ "]50-75]",
x > 75.0001 ~ "]75-100]",
))) %>%
group_by(group) %>%
summarise(Mean = mean(y), SD = sd(y))
ggplot(dataII, aes(group, Mean, fill = "Red")) +
geom_col(position = "dodge", fill = "palegreen3", colour = "black") +
geom_errorbar(aes(ymin = Mean, ymax = Mean + SD), width=0.2) +
theme_minimal() +
xlab(expr(!!x)) + ylab("Effort d'observation")
}
Code : Tout sélectionner
barplot_effort_habitat(data = data_observation, habitat_type = superficie_essence, Effort = effort)
Cela fonctionne très bien, mais j'aimerais rajouter une information sur le graphique. J'aimerais à la base des barplots afficher le nombre d'effectif "n" qui a aidé à calculer les moyennes. Par exemple pour [0] la moyenne a été calculé sur 4 observations : n = 4.
Merci à tous