Hey R users, I am a little bit confused. require(plotrix) plot(0,xlim=c(-10,10),ylim=c(-10,10),type="n",xlab="",ylab="") draw.circle(0,0,5) lines(c(0,0),c(0,5)) lines(c(0,5),c(0,0)) This is not really a circle with a radius of 5. best regards -- View this message in context: http://r.789695.n4.nabble.com/Is-something-wrong-wiht-draw-circle-tp4642514.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Sep 7, 2012 at 9:04 AM, Chris82 <rubenbauar at gmx.de> wrote:> Hey R users, > > I am a little bit confused. > > > require(plotrix) > > plot(0,xlim=c(-10,10),ylim=c(-10,10),type="n",xlab="",ylab="") > draw.circle(0,0,5) > > lines(c(0,0),c(0,5)) > lines(c(0,5),c(0,0))The culprit are unequal margins. Issue par(mar = c(4,4,4,4)) before your code, and you will get a consistent circle. More generally, when the scale of x axis and y axis are not the same (i.e., 1 unit corresponds to different distances __on screen__), drawing a naive circle would result in something that looks like an ellipse on screen. Plotrix can apparently draw a real circle but then the radius is "correct" only in the x direction. HTH, Peter
Add asp=1 to your call to plot() to force equal scales on both axes. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Peter Langfelder > Sent: Friday, September 07, 2012 10:03 AM > To: Chris82 > Cc: r-help at r-project.org > Subject: Re: [R] Is something wrong wiht draw.circle()? > > On Fri, Sep 7, 2012 at 9:04 AM, Chris82 <rubenbauar at gmx.de> wrote: > > Hey R users, > > > > I am a little bit confused. > > > > > > require(plotrix) > > > > plot(0,xlim=c(-10,10),ylim=c(-10,10),type="n",xlab="",ylab="") > > draw.circle(0,0,5) > > > > lines(c(0,0),c(0,5)) > > lines(c(0,5),c(0,0)) > > The culprit are unequal margins. Issue > > par(mar = c(4,4,4,4)) > > before your code, and you will get a consistent circle. > > More generally, when the scale of x axis and y axis are not the same > (i.e., 1 unit corresponds to different distances __on screen__), > drawing a naive circle would result in something that looks like an > ellipse on screen. Plotrix can apparently draw a real circle but then > the radius is "correct" only in the x direction. > > HTH, > > Peter > > ______________________________________________ > 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.
On 09/08/2012 02:04 AM, Chris82 wrote:> Hey R users, > > I am a little bit confused. > > > require(plotrix) > > plot(0,xlim=c(-10,10),ylim=c(-10,10),type="n",xlab="",ylab="") > draw.circle(0,0,5) > > lines(c(0,0),c(0,5)) > lines(c(0,5),c(0,0)) > > > This is not really a circle with a radius of 5. >Hi Chris82, If you measure it, you will find that it is indeed a circle, and that your two "radii" are not of equal length (see Euclid, -300). The draw.circle function attempts to correct for the aspect ratio of the plot, but not for the aspect ratio of the device, so there may be slight variations on different devices. Jim