[R] Question about banking to 45 degrees.
Charilaos Skiadas
cskiadas at gmail.com
Tue May 20 22:16:28 CEST 2008
On May 20, 2008, at 2:34 PM, Deepayan Sarkar wrote:
> On 5/20/08, Joshua Hertlein <jhertlein at hotmail.com> wrote:
>>
>> Hello,
>>
>> I am very interested in "banking to 45 degrees" as defined by
>> William S. Cleveland
>> in "Visualizing Data." I like to do it in R as well as Excel,
>> etc. With R I have come
>> across the following method:
>>
>> xyplot(x, y, aspect="xy") (part of "lattice" package)
>>
>> which will bank my graph to 45 degrees. My question is how do I
>> obtain the
>> aspect ratio that banks this graph to 45 degrees? I understand
>> that R does it
>> for me, but I would like to explicitly know the aspect ratio so
>> that I can configure
>> other graphs in Excel or other software.
>
>
>> foo <- xyplot(sunspot.year ~ 1700:1988, type = "l", aspect = "xy")
>> foo$aspect.ratio
> [1] 0.04554598
>
>
>> aspect ratio = v / h (v is vertical distance of plot, h is
>> horizontal distance of plot.
>> NOT in the data units, but true, actual distance).
>>
>> I've also come across "banking ()", but I don't understand it,
>> nor the significance
>> of the value it returns. Regardless, it doesn't seem to be the
>> aspect ratio that
>> I am looking for.
>
> banking(dx, dy) basically gives you the median of abs(dy/dx). The idea
> is that dx and dy define the slopes of the segments you want to bank
> (so typically, dx = diff(x) and dy = diff(y) if x and y are the data
> you want to plot). banking() gives you a single (summary) slope; you
> then choose the aspect ratio of your plot so that this slope (in the
> data coordinates) has a physical slope of 1. To do this, you solve an
> equation involving the data range in the x- and y-axes of your plot.
Here is how I see it. Let me define a "visual y-unit" as the height
of a unit of data in the y-direction, and similarly for a visual x-unit.
Then the aspect ratio is the quotient of the visual y-unit over the
visual x-unit. So the aspect ratio is the number of visual x-units
that have the same length as one visual y-unit.
If a line has real (data) slope r, and the aspect ratio is b, then
the line appears with slope rb.
Now, there are two things one can compute (for simplicity I assume
all slopes are positive, insert absolute values as necessary):
1. The value of the aspect ratio, that makes the median of the visual
slopes be 1. This would be obtained by requiring the median of all
the rb to be 1, which means that the aspect ratio would be 1/median
(slopes).
2. The median of the aspect ratios, that make each individual line
have slope 1. So for each line with slope r, we consider the aspect
ratio 1/r, and then take the median of that. So this would be median
(1/slopes).
Now, unless I am missing something, the banking function computes the
second one of these, while I think the documentation (and my
intuition) say that we want the first of these. In the case where
there is an odd number of data, they would agree, but otherwise one
is related to the arithmetic mean of the two middle observations,
while the other is referring to the harmonic mean of the two
observations. Those will likely be close to each other in most cases,
so perhaps this is a moot point in practice, but am I wrong in
thinking that 1/median(abs(dy[id]/dx[id])) would be the right thing
to have in the code to the banking function?
> -Deepayan
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College
More information about the R-help
mailing list