[R] "user units" in plotrix

Jim Lemon jim at bitwrit.com.au
Mon Jan 21 01:11:22 CET 2013


On 01/21/2013 08:59 AM, Murat Tasan wrote:
> hi all - i'm having some difficulty figuring out how to convert
> between "user units" (which i can't find a definition for in the
> plotrix package) and either (a) device units (e.g. inches with PDFs)
> or (b) user coordinates along any particular axis.
>
> as an example, suppose i set up a PDF device with inches, the device
> has both outer and inner magins, and the plot region has drastically
> different x and y coordinate ranges (e.g. xlim = c(0, 1), ylim =  c(0,
> SOME_VERY_LARGE_NUMBER)).
>
> now i'd like to draw.circle(...) but i can't figure out what units the
> radius argument takes.
> "user units" doesn't appear to be inches in this case, and it it
> corresponds to user coordinates, i don't know which axis' scaling is
> to be used as the reference.
>
> ideally, one would be able to specify the radius in user coordinates
> while specifying _which_ axis to use as the standard (e.g. an axis =
> "y" or axis = "x" argument).
>
> getFigCtr(...) can help in figuring this out, but its argument takes
> the relative position of the "figure" region, rather than the "plot"
> region, which is more apt for properly placing shapes.
>
> i know the grid package has extensive unit conversion code, but i'm
> trying to update a series of figures using only base graphics...
>
> i can't seem to find a rigorous definition of "user units" anywhere in
> the plotrix package.
> anyone know of where i can find this info?
>
Hi Murat,
"User units" are the units of the plot itself. If you have very large 
differences between the x and y units of a plot, functions like 
"draw.circle" will try to adjust for this when drawing the circle. 
Currently draw.circle uses the x units of the plot for the radius and 
adjusts the y units. So if you asked for a circle on a plot with the 
user units above - xlim=c(0,1),ylim=c(0,1000000) - with a radius of 0.5 
and centered at 0.5,500000, the circle would fill almost the whole plot. 
In contrast, if you reverse the ratio, you would have to ask for a 
radius of 50 just to see a dot in the middle of the plot.

I had a quick look for a definition of "user units" and found that "user 
coordinates" is used several times in the documentation for the "par" 
function. However, I could not find a definition other than the implicit 
one of the coordinates or units that the user specifies for a plot.

Jim



More information about the R-help mailing list