I am plotting a bar graph in RSTUDIO. However, the axes x show in different month order. Using the command reoder_within, doesn’t work for the purpose.
Follow below the ME.
ggplot(de, aes(fill=Cidade, y = Leitura , x = Mes ))+geom_bar(position='dodge', stat='identity')
Generate the follow plot:
My purpose is modify the axes x to: Jan, Fev, March …..
The set of data is:
Cidade Mes Leitura
<chr> <chr> <dbl>
1 Petrolina Janeiro 74.2
2 Petrolina Fevereiro 73.2
3 Petrolina Março 68.7
4 Petrolina Abril 42.9
5 Petrolina Maio 9.84
6 Petrolina Junho 8.02
Thank you for help
Yours Faithfully
>Solution :
We can use fct_inorder here:
ggplot will order x axis alphapetically. To get the order in your table use fct_inorder:
library(ggplot2)
library(forcats)
library(dplyr)
de %>%
mutate(Mes = fct_inorder(Mes)) %>%
ggplot(aes(fill = Cidade, y = Leitura, x = Mes)) +
geom_bar(position = 'dodge', stat = 'identity')
