Screen coordinates in R

I would like to draw two perpendicular lines on the current device. They should have the same visible length on the device, regardless of the aspect ratio of the output and the size of the device.

Is it even possible? In principle, this is the problem of drawing a perfect circle on the screen.

+4
source share
3 answers

You can get the current coordinates of the graphics window. Thanks to Josh O'Brien for providing me this code some time ago. First you create a window (or draw something), then run this line:

 myasp <- with(par(),(pin[2]/pin[1])/(diff(usr[3:4])/diff(usr[1:2])))

Then use this aspect information to adjust the lengths of the lines you are going to build.

+3
source

,

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)
+3

You may be interested in the functions grconvertXand grconvertY. Using them, you can specify the coordinates in inches or other units, and from this calculate the coordinates of the user to draw your line.

0
source

Source: https://habr.com/ru/post/1529001/


All Articles