The geom Texts labels are automatically in decreasing order instead of the data frame.
The question is concerning this part of the snippet "geom_text(aes(label = Freq)..."
EDIT: Here you can clearly see the that the order is not followed by geom_text. But Frequency descreasing in all categories :-/
ggplot(df_beine_clan, aes(x = Var2, y = Freq, fill = Var1))
geom_bar(stat = "identity")
geom_text(aes(label = Freq), vjust = 0, size = 5, nudge_y = 2, nudge_x = -0.5)
How to command that the order should not be changed when rendered on the bar chart?
CodePudding user response:
You could add position_stack
like this:
library(ggplot2)
ggplot(df_beine_clan, aes(x = Var2, y = Freq, fill = Var1))
geom_bar(stat = "identity")
geom_text(aes(label = Freq), position = position_stack(vjust = 0.5), size = 5)
Changing the variable label
to label <- sort(Value, decreasing = T)
or label <- c("Blue", "Green", "Red", "Blue", "Green", "Red")
gives you the two figures below.