R plot, x-axis and y-axis touching

Marnix de Zeeuw picture Marnix de Zeeuw · Jun 4, 2012 · Viewed 10.8k times · Source

My problem concerns the making of a graph for a publication in R. I have used the plot function like follows:

plot(x=data$SL, y=data$BD, xlab = "SL (mm)", ylab = "BD (mm)", pch=data$pch)

SL ranges from 51.7 to 73.7 and BD from 13.5 to 20.4. Unfortunately I am not allowed to post images yet.

However, wanting to get rid of the box I used "axes=F". Problem now is lack of control over the axis function. I used:

axis(side=1, lwd=3, xpd=TRUE, at=c(min(data$SL):max(data$SL)))
axis(side=2, lwd=3, xpd=TRUE, at=c(min(data$BD):max(data$BD)))

Problem is that I can't manage to get the y- and x-axis to come together on the same point as in the plot with the box. How to let the x- and y- axis to touch each other?

Answer

Roland picture Roland · Jun 4, 2012

Most likely setting xaxs = "i" and yaxs = "i" will help you getting the desired behaviour.

plot(c(1,2,3),c(2,4,6),axes=F,xaxs = "i",yaxs="i",xlim=c(0,3),ylim=c(0,6))
axis(side=1, lwd=3, xpd=TRUE, at=0:3)
axis(side=2, lwd=3, xpd=TRUE, at=seq(0,6,2))