-1

I am plotting a simple R graph with days of week in X axis and total sales in Y. I cannot figure out how to have x axis show days in ascending order. Any help is appreciated as I'm a newbie.

I tried below: image of plot

ggplot(df2, aes(x = df2$ends, y = df2$total.sale.price)) +
  geom_point() +
  stat_smooth(method = 'lm')
kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
AVS4
  • 1
  • Does this answer your question? [Reorder levels of a factor without changing order of values](https://stackoverflow.com/questions/2375587/reorder-levels-of-a-factor-without-changing-order-of-values) – Vinícius Félix Dec 12 '22 at 00:12
  • `stat_smooth(method = 'lm')` will only work with numeric variables, so it will not create a line here for you, if you need, you have to convert `ends` to numeric. – Ruam Pimentel Dec 12 '22 at 00:25

1 Answers1

1

Reorder your variable before running the plot. See below how to do it with base R.


df2$ends <- factor(df2$ends, levels= c("Sunday", "Monday", 
    "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))

Similar to this question and response

Ruam Pimentel
  • 1,288
  • 4
  • 16