[R] to draw a smooth arc

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 7 11:19:02 CEST 2007

There is now an xspline() function in R-devel, with an example showing how 
to add arrows.

I thought a bit more about a 'circular arc' function, but there really is 
a problem with that.  Few R plot regions have a 1:1 aspect ratio including 
some that are intended to do so (see the rw-FAQ).  symbols() is designed 
to draw circles in device coordinates, but attempting to specify circular 
arcs by endpoints in user coordinates is fraught.

On Wed, 2 May 2007, Paul Murrell wrote:

> Hi
> Paulo Barata wrote:
>> Dr. Murrell and all,
>> One final suggestion: a future function arc() in package graphics,
>> with centre-radius-angle parameterisation, could also include an
>> option to draw arrows at either end of the arc, as one can find
>> in function arrows().
> ... and in grid.xspline() and grid.curve().
> Paul
>> Thank you.
>> Paulo Barata
>> -----------------------------------------------------------------------
>> Paul Murrell wrote:
>>> Hi
>>> Paulo Barata wrote:
>>>> Dr. Snow and Prof. Ripley,
>>>> Dr. Snow's suggestion, using clipplot (package TeachingDemos),
>>>> is maybe a partial solution to the problem of drawing an arc of
>>>> a circle (as long as the line width of the arc is not that large,
>>>> as pointed out by Prof. Ripley). If the arc is symmetrical around
>>>> a vertical line, then it is not so difficult to draw it that way.
>>>> But an arc that does not have this kind of symmetry would possibly
>>>> require some geometrical computations to find the proper rectangle
>>>> to be used for clipping.
>>>> I would like to suggest that in a future version of R some function
>>>> be included in the graphics package to draw smooth arcs with
>>>> given center, radius, initial and final angles. I suppose
>>>> that the basic ingredients are available in function "symbols"
>>>> (graphics).
>>> Just to back up a few previous posts ...
>>> There is something like this facility already available via the
>>> grid.xspline() function in the grid package.  This provides very
>>> flexible curve drawing (including curves very close to Bezier curves)
>>> based on the X-Splines implemented in xfig.  The grid.curve() function
>>> provides a convenience layer that allows for at least certain
>>> parameterisations of arcs (you specify the arc end points and the angle).
>>> These functions are built on functionality within the core graphics
>>> engine, so exposing a similar interface (e.g., an xspline() function)
>>> within "traditional" graphics would be relatively straightforward.
>>> The core functionality draws the curves as line segments (but
>>> automatically figures out how many segments to use so that the curve
>>> looks smooth);  it does NOT call curve-drawing primitives in the
>>> graphics device (like PostScript's curveto).
>>> In summary:  there is some support for smooth curves, but we could still
>>> benefit from a specific arc() function with the standard
>>> centre-radius-angle parameterisation and we could also benefit from
>>> exposing the native strengths of different graphics devices (rather than
>>> the current lowest-common-denominator approach).
>>> Paul
>>>> Thank you very much.
>>>> Paulo Barata
>>>> (Rio de Janeiro - Brazil)
>>>> -----------------------------------------------------------------------
>>>> Prof Brian Ripley wrote:
>>>>> On Tue, 1 May 2007, Greg Snow wrote:
>>>>>> Here is an approach that clips the circle you like from symbols down to
>>>>>> an arc (this will work as long as the arc is less than half a circle,
>>>>>> for arcs greater than half a circle, you could draw the whole circle
>>>>>> then use this to draw an arc of the bacground color over the section you
>>>>>> don't want):
>>>>>> library(TeachingDemos)
>>>>>> plot(-5:5, -5:5, type='n')
>>>>>> clipplot( symbols(0,0,circles=2, add=TRUE), c(0,5), c(0,5) )
>>>>> I had considered this approach: clipping a circle to a rectangle isn't
>>>>> strictly an arc, as will be clear if the line width is large.
>>>>> Consider
>>>>> clipplot(symbols(0, 0 ,circles=2, add=TRUE, lwd=5), c(-1,5), c(-1,5))
>>>>> Note too that what happens with clipping is device-dependent.  If R's
>>>>> internal clipping is used, the part-circle is converted to a polygon.
>>>> ______________________________________________
>>>> R-help at 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
>>>> and provide commented, minimal, self-contained, reproducible code.

Brian D. Ripley,                  ripley at 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

More information about the R-help mailing list