how to print all values of x axis (years in this case)

...

code that I am using to create a graph.

arimamodel<-ts(dt$Record,start = c(2009,1),frequency = 12)
      arimamodel
      fit_Amodel<-auto.arima(arimamodel,seasonal=TRUE) 
      fit_Amodel
      predict(fit_Amodel)
 autoplot(forecast(fit_Amodel,h=24)) +
        ggtitle("Delivery Records Year-Wise") +
        xlab("(Delivery Year)") + ylab("(Delivery Records)") +
        theme_bw() +
        theme(plot.title = element_text(hjust = 0.5))

I have also tried ...

scale_x_continuous(breaks = seq(from= 2009,to=2020, by =2 ))

it's throwing an error: 'origin' must be supplied'

would someone please tell me how to plot it desired way.

If year is of class Date, then I think the code would be scale_x_date(date_breaks = "1 year"). Let me know if that works. If you can provide some sample data I can test other options if scale_x_date doesn't get the job done.

it is working fine but I don't want the month and days to be printed, just year would be great

thanks for your help bro, i appreciate your concern

is this method can be applied for the y axis as well,then what would be the function in that case like you used earlier for that specific scenario
scale_x_date.....

scale_y_?

To show just the year: scale_x_date(date_breaks="1 year", date_labels="%Y")

For the y-axis, which in this case is a continuous value, you could do, for example: scale_y_continuous(breaks=seq(20000, 200000, 10000), labels=scales::comma) + expand_limits(y=0).

See the help for scale_x_date and scale_y_continuous for additional options.

1 Like

thanks and it has served my purpose

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