I know I can specify the aspect ratio when plotting, e.g. plot(x,y,asp=5)
. Is there any way to retrieve the aspect ratio after allowing autoscale (as in plot(x,y)
) ? The reason I ask is that I was playing with text(x,y,'mystring',srt=local_slope)
, where I calculate the local_slope
based on the underlying curve and the x
value of interest. Trouble is, for asp!=1
this rotates the text at a different angle from the displayed slope of my plotted data set. Sample:
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
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 width and height of plotting region in inches ...
ff <- par("pin")
ff[2]/ff[1] ## 1.00299
Now resize the plot manually ...
ff <- par("pin")
ff[2]/ff[1] ## 0.38
You can also use par("usr")
to sort out the aspect ratio
in user units, but I haven't figured out quite the right
set of ratios ... the guts of MASS::eqscplot
might be enlightening too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With