Hi I want to make this kind of graphs. I know it is bar charts plot. And can be used with bar_charts. But the only I can do is to make a simple bar charts with the maximum value above the bars. I suppose it is more complicated and I am not sure whether ggplot can make it. Any idea ?
[
tab1<read.csv("/Users/vladalexandru/Documente/vlad_R/R_markdown/Rmrkd/Tab/Tx_tn.csv")
tab1$dat <- as.Date(tab1$dat)
tab2 <- aggregate(tab1, by = list(format(tab1$dat, "%m")), FUN = "mean")
ggplot(data=tab2, aes(x=Group.1, y= tx)) +
geom_bar(stat="identity", fill="yellow")+
geom_text(aes(label=round(tx,0)), vjust=-0.3, size=3.5)+
labs(x = "month")+
scale_y_continuous(name = "°C")+
theme_minimal()
It is actually possible to make a gradient-filled boxplot like this in ggplot. It's a hassle though. You have to add a transparent bar at the bottom of a stacked bar chart, then construct the gradient by slicing the bar into thin pieces and coloring them:
set.seed(123)
a <- sample(10:20, 12, TRUE)
b <- sample(1:10, 12, TRUE)
data.frame(vals = c(sapply(1:12, function(i) c(rep(a[i]/39, 39), 20 - b[i]))),
month =factor( rep(month.abb, each = 40), levels = month.abb),
fills = rep(c(1:39, "top"), 12)) %>%
ggplot(aes(x = month, y = vals, fill = fills)) +
geom_col(fill = "gray95", aes(y = Inf), width = 0.7) +
geom_col(position = position_stack(), width = 0.5) +
scale_fill_manual(values = c("#00000000",
colorRampPalette(colors = c("forestgreen",
"gold", "orange"))(38),
"#00000000"),
guide = guide_none()) +
theme_classic()