Solved – How to change X-axis format in plot

r

I have fit a linear model and I now doing a lack-of-fit test. If the model has a good fit, the residual deviance should follow a $\chi^2$ distribution. The model I just ran has a very poor fit, and now I want to show this visually. I have used the following R code to plot the value of the residual deviance and the $\chi^2$ distribution it should come from (under the hypothesis of good fit).

df <- 384162
resdev <- 750749
x <- seq(from=350000, to=800000, by=1)
y <- dchisq(x, df=df)
plot(x, y, type='l')
abline(v=resdev, col='red')

Everything is working fine, except now the X-axis values are displaying in scientific notation. How to I control the formating of the axis values? I understand it may be crowded if I use normal notation, so can I format labels something like 350k for 350,000?

Best Answer

Look at function axis help page. Something like the following should work:

axis(1, at = x <- seq(3.5e5, 8e5, by = 5e4),  labels = paste(x/1000, "k", sep = "" ))