R plot, x-axis and y-axis touching

时间:2023-01-12 20:17:40

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

我的问题涉及为R中的出版物制作图表。我使用了如下的绘图函数:

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.

SL的范围从51.7到73.7,BD从13.5到20.4。不幸的是我还不允许发布图片。

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

但是,想要摆脱我用“轴= F”的盒子。现在的问题是缺乏对轴功能的控制。我用了:

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?

问题是我无法设法让y轴和x轴在与框图中的相同点上聚集在一起。如何让x轴和y轴相互接触?

3 个解决方案

#1


5  

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

最有可能设置xaxs =“i”和yaxs =“i”将帮助您获得所需的行为。

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))

#2


5  

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.

尝试框(bty ='L')仅绘制框的左下部分。您也可以使用线条,线段或abline自行绘制线条,并使用grconvertX和grconvertY函数查找绘制线条的位置。

#3


1  

I suggest that you follow the procedure you outlined and then use:

我建议您按照您概述的程序进行操作,然后使用:

box(which = "plot", bty = "l")

box(=“plot”,bty =“l”)

e.g.:

plot.new()
plot.window(xlim = c(1, 18), ylim = c(2, 20))
points(1:18, 2:19, pch = 1, col = "#FF7F24", cex = 1.2)
lines(1:18,  2:19, col = "#FF7F24", lwd = 2)
axis(side      = 1,
     lwd       = 0,
     lwd.ticks = 1,
     at        = 1:18,
     cex.axis = 0.9)
title(main = "Plot",
      ylab = "Y-Axis")
legend("top",
       legend = c("Legend"),
       col = c("#FF7F24"),
       text.col = c("#FF7F24"),
       pch    = 1,
       bty    = "n",
       cex    = 1.2)
axis(side      = 2,
     lwd       = 0,
     lwd.ticks = 1)
box(which = "plot", bty = "l")

You should pass the options lwd = 0 and lwd.ticks = 1 to your seperate axis() calls in order to prevent some parts of your axes to appear fatter than other parts of your axis because some get overlayed by your call to box() and some do not.

您应该将选项lwd = 0和lwd.ticks = 1传递给您的单独轴()调用,以防止轴的某些部分比轴的其他部分显得更胖,因为有些部分会被您对box()的调用覆盖有些人没有。

The solution of using box() at the end is, I think, more general in that you can use it when e.g. you cannot or do not want to pass bty = "l" in your plot.default or plot.window call.

我认为最后使用box()的解决方案更为通用,因为你可以在例如你不能或不想在你的plot.default或plot.window调用中传递bty =“l”。

#1


5  

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

最有可能设置xaxs =“i”和yaxs =“i”将帮助您获得所需的行为。

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))

#2


5  

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.

尝试框(bty ='L')仅绘制框的左下部分。您也可以使用线条,线段或abline自行绘制线条,并使用grconvertX和grconvertY函数查找绘制线条的位置。

#3


1  

I suggest that you follow the procedure you outlined and then use:

我建议您按照您概述的程序进行操作,然后使用:

box(which = "plot", bty = "l")

box(=“plot”,bty =“l”)

e.g.:

plot.new()
plot.window(xlim = c(1, 18), ylim = c(2, 20))
points(1:18, 2:19, pch = 1, col = "#FF7F24", cex = 1.2)
lines(1:18,  2:19, col = "#FF7F24", lwd = 2)
axis(side      = 1,
     lwd       = 0,
     lwd.ticks = 1,
     at        = 1:18,
     cex.axis = 0.9)
title(main = "Plot",
      ylab = "Y-Axis")
legend("top",
       legend = c("Legend"),
       col = c("#FF7F24"),
       text.col = c("#FF7F24"),
       pch    = 1,
       bty    = "n",
       cex    = 1.2)
axis(side      = 2,
     lwd       = 0,
     lwd.ticks = 1)
box(which = "plot", bty = "l")

You should pass the options lwd = 0 and lwd.ticks = 1 to your seperate axis() calls in order to prevent some parts of your axes to appear fatter than other parts of your axis because some get overlayed by your call to box() and some do not.

您应该将选项lwd = 0和lwd.ticks = 1传递给您的单独轴()调用,以防止轴的某些部分比轴的其他部分显得更胖,因为有些部分会被您对box()的调用覆盖有些人没有。

The solution of using box() at the end is, I think, more general in that you can use it when e.g. you cannot or do not want to pass bty = "l" in your plot.default or plot.window call.

我认为最后使用box()的解决方案更为通用,因为你可以在例如你不能或不想在你的plot.default或plot.window调用中传递bty =“l”。