Re: [R] Drawing a circle on an existing graph.

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Sat, 12 Mar 2011 20:59:29 -0700

If you are always using asp=1 then you can just do something like:

x <- rnorm(100, 1, 5)
y <- rnorm(100, 3, 4)

plot( x,y, asp=1)

r=2
nseg=360
x.cent <- 5
y.cent <- 7

xx <- x.cent + r*cos( seq(0,2*pi, length.out=nseg) ) yy <- y.cent + r*sin( seq(0,2*pi, length.out=nseg) )

lines(xx,yy, col='red')

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> project.org] On Behalf Of Allan Kamau
> Sent: Saturday, March 12, 2011 1:08 PM
> To: r-help_at_r-project.org
> Subject: Re: [R] Drawing a circle on an existing graph.
>
> On Sat, Mar 12, 2011 at 10:22 PM, David Winsemius
> <dwinsemius_at_comcast.net> wrote:
> >
> > On Mar 12, 2011, at 10:56 AM, Allan Kamau wrote:
> >
> >>> --- On Sat, 3/12/11, Allan Kamau <kamauallan_at_gmail.com> wrote:
> >>>
> >>>> From: Allan Kamau <kamauallan_at_gmail.com>
> >>>> Subject: [R] Drawing a circle on an existing graph.
> >>>> To: r-help_at_r-project.org
> >>>> Received: Saturday, March 12, 2011, 3:08 AM
> >>>> I would like to draw a circle on a
> >>>> graph I am plotting in R and use
> >>>> the current plot's coordinate system.
> >>>> The most basic functionality I am looking for is the
> >>>> ability to plot a
> >>>> circle on an already existing graph by simply providing the
> >>>> xy
> >>>> coordinates for it's centre and the radius.
> >>>>
> >>>> I am also looking for a way to obtain x,y values of a point
> >>>> (of a
> >>>> circle) by specifying only the origin x,y the angle and
> >>>> radius.
> >>>>
> >>>> Please point me so such a library and perhaps some simple
> >>>> one line code.
> >>>>
> >>>> Allan.
> >>>>
> >> On Sat, Mar 12, 2011 at 5:28 PM, John Kane <jrkrideau_at_yahoo.ca>
> wrote:
> >>>
> >>> Is this of any use?
> >>> http://tolstoy.newcastle.edu.au/R/help/06/04/25821.html
> >>>
> >>
> >> Thank you John, that is what I was looking for.
> >> The code does draw a neat circle that is not stretched. After
> plotting
> >> the circle on an existing plot I notice that the original plot was
> >> indeed stretched somehow by approximately some 1:1.1 ratio (I
> think).
> >> Now I am looking for a way to enforce none stretching in my original
> >> graph.
> >
> > `plot.window` has an `asp` argument that is useful for that purpose.
> Most
> > plotting with base graphics will pass an asp=1 argument along as part
> of the
> > `...` arguments,
> >
> > --
> >
> > David Winsemius, MD
> > West Hartford, CT
> >
> >
> Thank you David, asp=1 argument in my plot function brought about 1:1
> aspect ratio to the graph and now the circle sits very neatly within
> it. All is well.
> John is there another version of your circle drawing code that accepts
> values in accordance with the current plot's scale units in place of
> the current real distance measurement (inches) units.
>
> Allan.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Sun 13 Mar 2011 - 04:04:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Mar 2011 - 04:10:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive