I would like to draw two perpendicular lines on the current device. They should both have the same apparent length on the device, irrespective of aspect ratio of the output and the device size.
Is this at all doable? In principle this is the problem of drawing a perfect circle on the screen.
You could retrieve the current graphics window coordinates. Thanks to Josh O'Brian for providing me with this code a while back. First you create a window (or plot something), then run this line:
myasp <- with(par(),(pin[2]/pin[1])/(diff(usr[3:4])/diff(usr[1:2])))
Then use that aspect information to adjust the lengths of the lines you're going to plot.
there are several ways, i find it easier in grid graphics
library(grid)
grid.circle()
vp <- viewport(width=unit(0.5, "snpc"), height=unit(0.5, "snpc"))
grid.rect(vp=vp, gp=gpar(lty=2))
grid.segments(x0=c(0,0), x1=c(1,1),
y0=c(0,1), y1=c(1,0),
default.units="npc", vp=vp)
You might be interested in the grconvertX
and grconvertY
functions. Using these you can specify coordinates in inches or other units and from that compute the user coordinates for drawing your line.
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