0

I want to plot my time series which have 2 column (month,values). Instead of starting from January, I dont know why it is starting from April in ggplot. If anyone have any ideas i am very pleased to hear it. Thank you.

dput(data_frame)

This is my data frame which made by reading an excel sheet.


dates <- month.name[data$Month]
diff1 <- mod1-obs1

data_frame <- data.frame( col1=dates,
                          col2 = diff1)
# plot the data using ggplot2

# windows()
ggplot(data=data_frame, aes(x=dates, y=diff1, group=1)) +
  geom_line()+
  geom_point()

enter image description here This is the result, which I don't know why starting from April.

correcting my script

  • Welcome to StackOverflow. Please don't poste images of your data. Instead please make your question *reproducible* by including copy-pasteable version of your data in the question. E.g. you can use `dput(data_frame)` here. – Dan Adams Nov 21 '22 at 17:28
  • 1
    This is a frequently asked question. Every time you plot a discrete variable on an axis, ggplot will sort it alphabetically. The way to make sure the order is what you want is to convert from `character` to `factor`, controlling the order with `factor(., levels=)`. See https://stackoverflow.com/q/3253641/3358272, https://stackoverflow.com/q/12774210/3358272, https://stackoverflow.com/q/18401931/3358272 – r2evans Nov 21 '22 at 17:31
  • Specifically https://stackoverflow.com/a/48998414/3358272 – r2evans Nov 21 '22 at 17:32
  • 1
    In this case you can take advantage of a built-in vector of month names with something like `dates = factor(dates, levels = month.name)` – Dan Adams Nov 21 '22 at 17:33
  • kettaren ray, if you are confident that none of those links address your issue, @ping me and we can sort out the differences and (if justified) reopen this question. – r2evans Nov 21 '22 at 17:35
  • thank you for your help! It has already sort out! danke – kettaren ray Nov 21 '22 at 17:45

0 Answers0