Base :: plot - can I get the proportional ratio of as-plot?

I know that I can specify the aspect ratio when plotting, for example. plot(x,y,asp=5). Is there a way to get the aspect ratio after autoscaling is enabled (as in plot(x,y))? The reason I ask is because I played with text(x,y,'mystring',srt=local_slope), where I calculate local_slopebased on the base curve and the value of interest x. The problem is that for asp!=1this the text is rotated at a different angle from the displayed slope of my constructed dataset. Example:

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
+4
source share
1 answer
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

Get the width and height of the print area in inches ...

ff <- par("pin")
ff[2]/ff[1]  ## 1.00299

Now resize the chart manually ...

ff <- par("pin")
ff[2]/ff[1]  ## 0.38

par("usr") , ... MASS::eqscplot .

+7

All Articles