How to place the intercept of x and y axes at (0 , 0) and extend the x and y axes to the edge of the plot [duplicate]

為{幸葍}努か 提交于 2019-11-28 21:21:30

By default, axis() computes automatically the tick marks position, but you can define them manually with the at argument. So a workaround could be something like :

curve(x^2, -5, 5, axes=FALSE)
axis(1, pos=0, at=-5:5)
axis(2, pos=0)

Which gives :

The problem is that you have to manually determine the position of each tick mark. A slightly better solution would be to compute them with the axTicks function (the one used by default) but calling this one with a custom axp argument which allows you to specify respectively the minimum, maximum and number of intervals for the ticks in the axis :

curve(x^2, -5, 5, axes=FALSE)
axis(1, pos=0, at=axTicks(1,axp=c(-10,10,10)))
axis(2, pos=0)

Which gives :

Sacha Epskamp

The arguments yaxs and xaxs control spacing around plots. Set to "i" to omit this:

curve(x^2, -5, 5, yaxs = "i")

See also: https://stackoverflow.com/a/12300673/567015

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!