本文介绍了对齐grid()以绘制刻度线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

plot(1:10,las=1,xaxp  = c(0, 10, 10),xlim=c(0,10), ylim=c(0,10))
grid(lwd=2, nx=10, ny=10)

试图更改xlim和网格中nx arg的不同数字(单元数),但网格根本无法对齐.

Tried changed the xlim and different numbers for the nx arg in grid (number of cells), but the grid simply doesn't line up.

相关,但未回答问题:

相关,并使用解决方法: 将网格与刻度线对齐

解决方法是最有效的选择吗?

Is the workaround the most efficient option?

推荐答案

您可以使用abline绘制网格.您可以使用h(对于水平线)和v(对于垂直线)指定网格应位于的位置

You could use abline to draw grids. You can specify where the grids should be with h (for horizontal lines) and v (for vertical lines)

#Plot
plot(1:10,las=1,xaxp  = c(0, 10, 10),xlim=c(0,10), ylim=c(0,10))
#Add horizontal grid
abline(h = c(0,2,4,6,8,10), lty = 2, col = "grey")
#Add vertical grid
abline(v = 1:10,  lty = 2, col = "grey")

另一种解决方法是使用axis,其中tck的值为1.使用axis,您可以使用at

Another workaround is to use axis where tck value is 1. With axis, you can specify where the grids should be with at

#Plot
plot(1:10,las=1,xaxp  = c(0, 10, 10),xlim=c(0,10), ylim=c(0,10))

#Add horizontal grid
axis(2, at = c(0,2,4,6,8,10), tck = 1, lty = 2, col = "grey", labels = NA)

#Add vertical grid
axis(1, at = 1:10, tck = 1, lty = 2, col = "grey", labels = NA)

#Add box around plot
box()

这篇关于对齐grid()以绘制刻度线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:48