1
I am not able to perform the grouping of the bars of the graph below even using the argument position = "dodge"
in the geom_bar
.
I found searches only with individual bars, I’m having difficulty creating this graph with points+lines when the bars are grouped.
Follow the command I am using and an example of how I would like to leave the chart.
dt <- data.frame(periodo = c ("junho", "julho", "agosto"),
peso = c(1, 5, 4, 3, 4, 3),
atr = c(0.95, 0.5, 0.7, 0.75, 0.6, 0.8))
ggplot() +
geom_bar(mapping = aes(x = dt$periodo, y = dt$peso),
stat = "identity",
fill = "lightblue",
position= "dodge",
width = 0.8) +
geom_line(mapping = aes(x = dt$periodo, y = dt$atr),
size = 1, color = "blue") +
geom_point(mapping = aes(x = dt$periodo, y = dt$atr),
size = 1, color = "black")+
scale_x_continuous(name = "Período") +
scale_y_continuous(name = "Peso",
sec.axis = sec_axis(~./5, name = "ATR",
labels = function(b) {paste0(round(b*100, 0), "%")})) +
theme(axis.title.y = element_text(color = "grey"),
axis.title.y.right = element_text(color = "blue"),
plot.title = element_text(vjust = 1.5, hjust = 0.5))+
labs(x = "Período", y = "",
title = "Dry - off",
subtitle = "Comparativo - Peso x ATR")
[