[R] drawing ellipses

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Jun 19 17:10:57 CEST 2002


> I now want to trace some ellipses to emphasize groups of data. I found how
> to trace circles with 'symbols()', but no ellipse. I'm planning on writing
> my own function based on 'polygon()' and the ellipse equation. Does anybody
> already have done similar work or have another solution ?

I believe the ellipse library will do this for you. Try

> install.packages("ellipse")

Otherwise, I have a function which will do something similar. I wrote it
ages ago but it still works fine:

# begin ellipse
ellipse <- function(x,y,
                    npoints=100,plot=T) {
  # x = x coordinate of center
  # y = y coordinate of center
  # width = length of major axis
  # height = length of minor axis
  # theta = rotation
  # npoints = number of points to send to polygon
  # plot = if TRUE, add to current device
  #      = if FALSE, return list of components
  a <- width/2
  b <- height/2
  xcoord <- seq(-a,a,length=npoints)
  ycoord.neg <- sqrt(b^2*(1-(xcoord)^2/a^2))
  ycoord.pos <- -sqrt(b^2*(1-(xcoord)^2/a^2))
  xx <- c(xcoord,xcoord[npoints:1])
  yy <- c(ycoord.neg,ycoord.pos)
  x.theta <- xx*cos(2*pi-theta)+yy*sin(2*pi-theta)+x
  y.theta <- yy*cos(2*pi-theta)-xx*sin(2*pi-theta)+y
# end ellipse


Sundar Dorai-Raj, Ph.D.     
Statistical Methods Engineer
PDF Solutions, Inc.
Richardson TX
(972) 889-3085 x216
(214) 392-7619 cell
sundar.dorai-raj at pdf.com
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list