强制x轴和y轴在R中的(0,0)处相遇

时间:2022-10-19 07:40:01

It's reasonable to set the plot region just around the data points, and not requiring the two meet at the origin, but sometimes it's desirable to have exactly that.

将绘图区域设置在数据点周围是合理的,并且不需要两者在原点相遇,但有时候确实需要这样。

I am trying to achieve that with the grid package but not getting what I want:

我试图用网格包实现这一点,但没有得到我想要的东西:

require(grid)
grid.newpage()
pushViewport(plotViewport(c(5, 5, 5 ,5)))
pushViewport(dataViewport(1:10, 1:10))
grid.points(1:10, 1:10, default.units='native')
grid.xaxis(at=0:10)
grid.yaxis(at=0:10)

强制x轴和y轴在R中的(0,0)处相遇

How can this be done in both the grid system and the tranditional R graphics system?

如何在网格系统和传统的R图形系统中完成?

1 个解决方案

#1


1  

I think your problem comes from the extension argument in dataViewport

我认为你的问题来自dataViewport中的扩展参数

require(grid)
grid.newpage()
pushViewport(plotViewport(c(5, 5, 5 ,5)))
pushViewport(dataViewport(0:10, 0:10, extension=c(0,0)))
grid.points(1:10, 1:10, default.units='native')
grid.xaxis(at=0:10)
grid.yaxis(at=0:10)

In base graphics,

在基础图形中,

plot(1:10, 1:10, xaxs="i", yaxs="i", xlim=c(0,10), ylim=c(0,10))

#1


1  

I think your problem comes from the extension argument in dataViewport

我认为你的问题来自dataViewport中的扩展参数

require(grid)
grid.newpage()
pushViewport(plotViewport(c(5, 5, 5 ,5)))
pushViewport(dataViewport(0:10, 0:10, extension=c(0,0)))
grid.points(1:10, 1:10, default.units='native')
grid.xaxis(at=0:10)
grid.yaxis(at=0:10)

In base graphics,

在基础图形中,

plot(1:10, 1:10, xaxs="i", yaxs="i", xlim=c(0,10), ylim=c(0,10))