How to set axis range R

Without data, I tried to reproduce your plot error:

plot(x=as.factor(2:8),y=2:8,xlim = c(1,10)

Which gives the following plot:

Changing your plot to:

boxplot(x= as.numeric(as.character(SS$Bed[XMSA=="MSSA"])),
y= ACC[XMSA=="MSSA"]
xlab="Bed",ylab="Growth",
las=1, yaxt="n",ylim=c(1,5),xlim=c(1,10))
axis(2, at=c(1,2,3,4,5),labels=c("NG","SG","LG","MG","HG"),las=1)

Might solve your problem.

Edit

It seems that the formula changes to factors and orders it from 1 to the number of items, so I’ll use your trick on the y axis to solve this.

boxplot(ACC[XMSA=="MSSA"]~SS$Bed[XMSA=="MSSA"],
xlab="Bed",ylab="Growth",
las=1, yaxt="n",ylim=c(1,5),xlim=c(0,9),xaxt="n")
axis(2, at=1:5,labels=c("NG","SG","LG","MG","HG"),las=1)
axis(1, at=0:9,labels=1:10,las=1)

Leave a Comment