Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R plot, x-axis and y-axis touching

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?

like image 575
Marnix de Zeeuw Avatar asked Jun 03 '12 22:06

Marnix de Zeeuw


2 Answers

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))
like image 182
Roland Avatar answered Oct 06 '22 01:10

Roland


Try box(bty='L') to draw only the left and bottom parts of the box. You could also just draw the lines yourself using lines, segments, or abline and using grconvertX and grconvertY functions to find the locations where to draw the lines.

like image 23
Greg Snow Avatar answered Oct 06 '22 01:10

Greg Snow