base :: plot - 我可以检索绘制的纵横比吗?

Car*_*oft 4 plot r

我知道我可以在绘图时指定纵横比,例如plot(x,y,asp=5).有没有办法在允许自动缩放后检索宽高比(如plot(x,y))?我问的原因是我在玩text(x,y,'mystring',srt=local_slope),我local_slope根据基础曲线和x感兴趣的价值来计算.麻烦的是,asp!=1为此,文本以与绘制的数据集的显示斜率不同的角度旋转.样品:

x<- -10:10
y<- x^2
plot(x,y,t='l',asp=0.1) 
# the slope at x=1 is 2 but the default plot aspect ratio is far from 1:1
text(1,1,'foo',srt= 180/pi*atan(2) )  #ugly-looking
text(-1,1,'bar',srt= (180/pi*atan(2/10))) #better
Run Code Online (Sandbox Code Playgroud)

Ben*_*ker 7

x<- -10:10
y<- x^2
plot(x,y,t='l',asp=0.1) 
### the slope at x=1 is 2 but the default plot aspect ratio is far from 1:1
text(1,1,'foo',srt= 180/pi*atan(2) )  #ugly-looking
text(-1,1,'bar',srt= (180/pi*atan(2/10))) #better
Run Code Online (Sandbox Code Playgroud)

以英寸为单位获取绘图区域的宽度和高度...

ff <- par("pin")
ff[2]/ff[1]  ## 1.00299
Run Code Online (Sandbox Code Playgroud)

现在手动调整图表大小...

ff <- par("pin")
ff[2]/ff[1]  ## 0.38
Run Code Online (Sandbox Code Playgroud)

您还可以使用par("usr")以用户单位对纵横比进行分类,但我还没有想出相当正确的比率......这些内容MASS::eqscplot可能也很有启发性.