# Re: [R] how to draw a circle

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sun 23 Apr 2006 - 06:05:17 EST

On Sat, 22 Apr 2006, John Fox wrote:

> Dear Jian,
>
> Here's an answer to the first part of what I understood to be your original
> question, which entails drawing a circle of a given (absolute) size in cm
> (i.e., regardless of the physical dimensions of the device and the units of
> the axes):
>
> circle <- function(x, y, radius, units=c("cm", "in"), segments=100){
> units <- match.arg(units)
> plot.size <- par("pin")
> plot.units <- par("usr")
> units.x <- plot.units[2] - plot.units[1]
> units.y <- plot.units[4] - plot.units[3]
> ratio <- (units.x/plot.size[1])/(units.y/plot.size[2])
> angles <- (0:segments)*2*pi/segments
> unit.circle <- cbind(cos(angles), sin(angles))
> shape <- matrix(c(1, 0, 0, 1/(ratio^2)), 2, 2)
> ellipse <- t(c(x, y) + size*t(unit.circle %*% chol(shape)))
> lines(ellipse)
> }

The solution via symbols is preferable, because drawing a circle is a primitive of the R graphics model, and symbols is the only way to get to it in base graphics (cf grid.circle). As a result is optimized to look good (the PDF device uses a dingbat for small circles, for example).

>
> Regards,
> John
>
> --------------------------------
> John Fox
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
> --------------------------------
>
>> -----Original Message-----
>> From: r-help-bounces@stat.math.ethz.ch
>> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Jian Zhang
>> Sent: Saturday, April 22, 2006 12:43 PM
>> To: r-help
>> Subject: [R] how to draw a circle
>>
>> how to draw a circle (e.g. radius=10cm) of one point?
>> And how to choose these points in the circle?

>> Thanks!
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
>

```--
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help