The x-axis does not start from the y=0 line in R

Viewed 64

I created a plot with the code below

mydata <- c(20,40,60,30,70) #put as an example
myrange <- range(mydata)
plot(mydata2, type="o", col="blue", axes=F, ann=F)
axis(2, las=1, at=0:myrange[2])                       
axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri")) 

However, the x-axis does not start from the y=0 line. What should I do?

I put the example figure below: Example plot

1 Answers

if I understand correctly, the axis lines don't touch. This might help...

add xaxs and yaxs argument to your plot call:

mydata2 <- c(20,40,60,30,70)

plot(mydata2, type="o", col="blue", axes=F, xaxs = "i",yaxs="i",ann=F, ylim=c(0, max(mydata2)))

axis(2, las=1, at=0:range(mydata2)[2])
                       
axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri"))
Related