1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| df <- data.frame("Date" = sample(seq(as.Date('2021/01/01'), # axe x
as.Date('2021/12/12'), by="day"), 12),
"Val" = sample(100:1000, 12), # axe y
"Qte" = sample(1:15, 12)) # labels
funct <- function(df, y, aesLabel, title){
return(
ggplot(df, aes_string(x = "Date", y = y)) +
geom_point() + geom_line() +
geom_text(
label=aesLabel, check_overlap = T,
hjust = 0.5, vjust = -1)+
#nudge_x = 0.25, nudge_y = 2.5) +
theme(axis.text.x = element_text(angle=45, hjust = 1)) +
labs(x = "", y = y) +
#scale_y_continuous() +
scale_x_date(labels = date_format("%d%b%y")) +
ggtitle(title)
)
}
funct(df = df, y = "Val", aesLabel = df$Qte, title = "") |
Partager