Re: [R] rotate pie chart

2005-05-26 Thread Martin Maechler

 Kati == Katrin Schweitzer [EMAIL PROTECTED]
 on Wed, 25 May 2005 08:25:07 +0200 writes:

 I think you have to get your hands dirty on this one, but it's not too
 hard.  Here's a function pie90() which is a tiny modification of pie().
 Does that do the trick?
 

Kati Yes, it works perfectly fine, at least for what I
Kati wanted... :) Thanks a lot, to Lars for asking, and
Kati to Paul for getting your hands dirty!

Kati Kati

Kati PS: I know one shouldn't use pie charts at all... :)

yes, indeed, really!

Kati but if I do so, is there a reason why they work
Kati counter-clockwise in R? Is that convention?  Sorry
Kati if its a silly question, my intuition (which might
Kati very likely be horrible) just expected them to start
Kati at 12 o'clock and fill the pie clockwisely.


you see how very tired I must be at the moment; otherwise I
wouldn't spend time for this (a function that shouldn't be used),
but anyway I did

I've worked on Paul's pie90() and on Kati's extra-wish
to produce a version of standard pie() that allows Kati and Lars
(and whoever) to produce  pie()s  starting at an arbitrary angle and
go clockwise instead of the usual ``mathematically positive''
direction.

Look for this (+ documentation) in a few days in R-devel.
Martin

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] rotate pie chart

2005-05-25 Thread Katrin Schweitzer


 I think you have to get your hands dirty on this one, but it's not too
 hard.  Here's a function pie90() which is a tiny modification of pie().
   Does that do the trick?


Yes, it works perfectly fine, at least for what I wanted... :)
Thanks a lot, to Lars for asking, and to Paul for getting your hands dirty!

Kati

PS: I know one shouldn't use pie charts at all... :) but if I do so, is 
there a  reason

why they work counter-clockwise in R? Is that convention?
Sorry if its a silly question, my intuition (which might very likely be 
horrible)

just expected them to start at 12 o'clock and fill the pie clockwisely.









 pie90 - function (x, labels = names(x), edges = 200, radius = 0.8,
 density = NULL,
  angle = 45, col = NULL, border = NULL, lty = NULL, main = NULL,
  ...)
 {
  if (!is.numeric(x) || any(is.na(x) | x = 0))
  stop('x' values must be positive.)
  if (is.null(labels))
  labels - as.character(1:length(x))
  x - c(0, cumsum(x)/sum(x))
  dx - diff(x)
  plot.new()
  pin - par(pin)
  xlim - ylim - c(-1, 1)
  if (pin[1]  pin[2])
  xlim - (pin[1]/pin[2]) * xlim
  else ylim - (pin[2]/pin[1]) * ylim
  plot.window(xlim, ylim, , asp = 1)
  nx - length(dx)
  if (is.null(col))
  col - if (is.null(density))
  c(white, lightblue, mistyrose, lightcyan,
  lavender, cornsilk)
  else par(fg)
  col - rep(col, length.out = nx)
  border - rep(border, length.out = nx)
  lty - rep(lty, length.out = nx)
  angle - rep(angle, length.out = nx)
  density - rep(density, length.out = nx)
  for (i in 1:nx) {
  n - max(2, floor(edges * dx[i]))
 # modified line below
  t2p - 2 * pi * seq(x[i], x[i + 1], length = n) + pi/2
  xc - c(cos(t2p), 0) * radius
  yc - c(sin(t2p), 0) * radius
  polygon(xc, yc, density = density[i], angle = angle[i],
  border = border[i], col = col[i], lty = lty[i])
 # modified line below
  t2p - 2 * pi * mean(x[i + 0:1]) + pi/2
  xc - cos(t2p) * radius
  yc - sin(t2p) * radius
  if (!is.na(lab - labels[i])  lab != ) {
  lines(c(1, 1.05) * xc, c(1, 1.05) * yc)
  text(1.1 * xc, 1.1 * yc, lab, xpd = TRUE, adj = ifelse(xc 
  0, 1, 0), ...)
  }
  }
  title(main = main, ...)
  invisible(NULL)
 }


 Paul


 Sean Davis wrote:
  You might want to look at grid graphics and gridBase.  I don't know in
  detail how to go about what you are asking, but grid allows you to
  rotate plots arbitrarily.  Here are a couple of links that I think are
  useful.
 
  http://www.stat.auckland.ac.nz/~paul/grid/grid.html
  http://www.stat.auckland.ac.nz/~paul/grid/doc/rotated.pdf
 
  Sean
 
  On May 24, 2005, at 10:09 AM, Lars wrote:
 
  hey,
 
  about two weeks ago i posted a question concerning the display of two
  piecharts on one plot. after now being able to do so, i need to rotate
  them. the first piece of my pie is suppose to start at 0° but at 90°.
  i tried several things, all failing in the end. anyone out there who
  has an idea?
 
  Lars
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
  http://www.R-project.org/posting-guide.html
 
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
  http://www.R-project.org/posting-guide.html


 --
 Dr Paul Murrell
 Department of Statistics
 The University of Auckland
 Private Bag 92019
 Auckland
 New Zealand
 64 9 3737599 x85392
 [EMAIL PROTECTED]
 http://www.stat.auckland.ac.nz/~paul/

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] rotate pie chart

2005-05-24 Thread Lars

hey,

about two weeks ago i posted a question concerning the display of two 
piecharts on one plot. after now being able to do so, i need to rotate 
them. the first piece of my pie is suppose to start at 0° but at 90°. i 
tried several things, all failing in the end. anyone out there who has 
an idea?


Lars

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] rotate pie chart

2005-05-24 Thread Sean Davis
You might want to look at grid graphics and gridBase.  I don't know in 
detail how to go about what you are asking, but grid allows you to 
rotate plots arbitrarily.  Here are a couple of links that I think are 
useful.


http://www.stat.auckland.ac.nz/~paul/grid/grid.html
http://www.stat.auckland.ac.nz/~paul/grid/doc/rotated.pdf

Sean

On May 24, 2005, at 10:09 AM, Lars wrote:


hey,

about two weeks ago i posted a question concerning the display of two 
piecharts on one plot. after now being able to do so, i need to rotate 
them. the first piece of my pie is suppose to start at 0° but at 90°. 
i tried several things, all failing in the end. anyone out there who 
has an idea?


Lars

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] rotate pie chart

2005-05-24 Thread Paul Murrell

Hi

gridBase won't help here (grid can't rotate traditional graphics output).

I think you have to get your hands dirty on this one, but it's not too 
hard.  Here's a function pie90() which is a tiny modification of pie(). 
 Does that do the trick?


pie90 - function (x, labels = names(x), edges = 200, radius = 0.8, 
density = NULL,

angle = 45, col = NULL, border = NULL, lty = NULL, main = NULL,
...)
{
if (!is.numeric(x) || any(is.na(x) | x = 0))
stop('x' values must be positive.)
if (is.null(labels))
labels - as.character(1:length(x))
x - c(0, cumsum(x)/sum(x))
dx - diff(x)
plot.new()
pin - par(pin)
xlim - ylim - c(-1, 1)
if (pin[1]  pin[2])
xlim - (pin[1]/pin[2]) * xlim
else ylim - (pin[2]/pin[1]) * ylim
plot.window(xlim, ylim, , asp = 1)
nx - length(dx)
if (is.null(col))
col - if (is.null(density))
c(white, lightblue, mistyrose, lightcyan,
lavender, cornsilk)
else par(fg)
col - rep(col, length.out = nx)
border - rep(border, length.out = nx)
lty - rep(lty, length.out = nx)
angle - rep(angle, length.out = nx)
density - rep(density, length.out = nx)
for (i in 1:nx) {
n - max(2, floor(edges * dx[i]))
# modified line below
t2p - 2 * pi * seq(x[i], x[i + 1], length = n) + pi/2
xc - c(cos(t2p), 0) * radius
yc - c(sin(t2p), 0) * radius
polygon(xc, yc, density = density[i], angle = angle[i],
border = border[i], col = col[i], lty = lty[i])
# modified line below
t2p - 2 * pi * mean(x[i + 0:1]) + pi/2
xc - cos(t2p) * radius
yc - sin(t2p) * radius
if (!is.na(lab - labels[i])  lab != ) {
lines(c(1, 1.05) * xc, c(1, 1.05) * yc)
text(1.1 * xc, 1.1 * yc, lab, xpd = TRUE, adj = ifelse(xc 
0, 1, 0), ...)
}
}
title(main = main, ...)
invisible(NULL)
}


Paul


Sean Davis wrote:
You might want to look at grid graphics and gridBase.  I don't know in 
detail how to go about what you are asking, but grid allows you to 
rotate plots arbitrarily.  Here are a couple of links that I think are 
useful.


http://www.stat.auckland.ac.nz/~paul/grid/grid.html
http://www.stat.auckland.ac.nz/~paul/grid/doc/rotated.pdf

Sean

On May 24, 2005, at 10:09 AM, Lars wrote:


hey,

about two weeks ago i posted a question concerning the display of two 
piecharts on one plot. after now being able to do so, i need to rotate 
them. the first piece of my pie is suppose to start at 0° but at 90°. 
i tried several things, all failing in the end. anyone out there who 
has an idea?


Lars

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html



--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html