probably this is because coord-polar calculates the distance between
vertices using Euclidean data and polar coordinate.
an easy hack is like this:
CoordPolar$distance <- function(., x, y, details) {
max_dist <- dist_polar(details$r.range, details$theta.range)
if (.$theta == "x") {
d <- .$transform(data.frame(theta=x, r=y), details)
dist_polar(theta = d$theta, r = d$r) / max_dist
} else {
d <- .$transform(data.frame(theta=y, r=x), details)
dist_polar(r = d$r, theta = d$theta) / max_dist
}
}
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
sorry for that my modification above is not general, and probably i
misunderstood something at that time.
please try this example:
ggplot(data.frame(xmin=0, ymin=0, xmax=2*pi, ymax=1), aes(xmin=xmin,
xmax=xmax,ymin=ymin,ymax=ymax))+geom_rect() + coord_polar()
ggplot(data.frame(xmin=0, ymin=0, xmax=314, ymax=1), aes(xmin=xmin,
xmax=xmax,ymin=ymin,ymax=ymax))+geom_rect() + coord_polar()
CoordPolar$distance calculate the distances between vertices, using
dist_polar that implementing the formula of polar distance.
In the first exmaple, max_dist = 1 because theta.range = 2 x pi = 0 on
polar coordinate, and the distance between two points on the
circumference is also 0 because of same reason.
using 2 x pi is somehow intentional.
Probably the worst thing occur in the second example. xmax=314, which
is near to 2 x n x pi, resulting in that distance is very small.
so the number of division point is also small. In this case, it is
hard for users to be aware what is happing.
so i think CoordPolar$distance needs to calculate the polar distance
as Euclidian distance... it is difficult to explain, though.
anyway, if the theta is near to 2 * n * pi, then the calculated
distance is very small.
I have committed some modification to github.
please find https://github.com/kohske/ggplot2/commit/057f8a2c746eca9998c17859a3b9442ff89cd8cd
this calculation is just approximation, but perhaps this is enough for
the purpose of drawing.
--
Kohske Takahashi <takahash...@gmail.com>
Research Center for Advanced Science and Technology,
The University of Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
by this example:
ggplot(data.frame(xmin=0, ymin=0, xmax=1, ymax=1), aes(xmin=xmin,
xmax=xmax,ymin=ymin,ymax=ymax))+geom_rect() + coord_polar()
in CoordPolar$distance, it calls
dist_polar(theta = x, r = y) / max_dist
where x = c(0, 1, 1, 0, 0) and y = (1, 1, 0, 0, 1)
that is, theta passed to dist_polar is 1, not 2 * pi, but should be 2 * pi.
this is what i said by
> probably this is because coord-polar calculates the distance between
> vertices using Euclidean data and polar coordinate.
so perhaps i found 2 different problems: regarding input as theta
(described here), and the distance is small when the theta is near to
2 * pi.
ggplot(data.frame(x=c(0,2*pi+0.1,0,(2*pi+0.1)*2),
y=c(0.5,0.5,1,1)),aes(x,y,group=y))+geom_line()+coord_polar()+ylim(0,1)
this is combination of these two points.
The theta of inner circle should be pi, but the distance is calculated
using input |x| = theta=2*pi+0.1, which is near to 2*pi, resulting in
small distance.
--
Kohske Takahashi <takahash...@gmail.com>
Research Center for Advanced Science and Technology,
The University of Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html