ggplot order months in x-axis

Hi people,

I´m new here and I don´t know how order the months from January to December.

Screen Shot 2020-04-17 at 21.03.55

p + geom_point(aes(x = Month, y = Sales/10^1), size = 3) +
ylab("New Sales in 2019") +
xlab("Months in 2019") +
ggtitle("Sales in The Company")

Please, May you help me?

Thanks a lot!

Set the levels of the factor variable, since you already have it ordered as you want, you can simply use forcats::fct_inorder()

See this example:

library(tidyverse)

# Sample data on a copy/paste friendly format
sample_df <- data.frame(stringsAsFactors = FALSE,
                        Month = c("Enero", "Febrero", "Marzo"),
                        Sales = c(1, 2, 3)
                        )
ggplot(sample_df) +
    geom_point(aes(x = fct_inorder(Month), y = Sales/10^1), size = 3) +
    ylab("New Sales in 2019") +
    xlab("Months in 2019") +
    ggtitle("Sales in The Company")

Created on 2020-04-18 by the reprex package (v0.3.0.9001)

Note: Next time, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.