2015-06-28 233 views
0

如何在R中强制显示零轴 = 0,x = 0,去除了图中的外部轴?我想获得与例如在Gnuplot中使用set xzeroaxis, set yzeroaxis相同的效果。在R中设置零轴

回答

0

其实,我已经解决了我的问题如下:

f<-function(x) x^3-2*x 

# take the axes off first 
plot(f,-2,2, axes=FALSE) 

# re-set the axes at a given point (pos=0) 
axis(1, pos=0, at=c(-2,-1,0,1,2)) 
axis(2, pos=0, at=c(-4,-2,2,4)) 

产生以下,这是我脑子里想的(标签和其余的可以随意调整)。

axes at zero

2

您可以通过使用axes=FALSE来抑制默认轴,然后使用axis绘制水平线和垂直线来表示轴。

# example plot 
plot(-2:2, -2:2, axes=FALSE) 

# add yaxis at position zero and rotate labels 45deg 
axis(side=2, pos=0, las=1, lty="dashed") 

# x axis 
axis(side=1, at=c(-2,-1,1,2), pos=0, lty="dashed") 

这将产生

enter image description here