adiamond at fas.harvard.edu wrote:> Dear wonderful R community,
>
> I've been creating color-coded concentric circles using the
"points" function,
> but I just realized that what I would really like to do is draw color-coded
> concentric half-circles.
> What should I do?
Write a 'halfCircle' function.
halfCircle <- function(x,y,r,start=0,end=pi,nsteps=30,...){
rs <- seq(start,end,len=nsteps)
xc <- x+r*cos(rs)
yc <- y+r*sin(rs)
lines(xc,yc,...)
}
Then try it out:
plot(1:10)
# default draws top halves:
halfCircle(5,5,2)
halfCircle(6,6,1,col="red")
# draw right half:
halfCircle(5,4,1,start=-pi/2,end=pi/2,lwd=2,col="blue")
Note that you'll have to call halfCircle once for each point, since
its not 'vectorised' in any way.
It's also capable of drawing any circle fragments. I should have
called it 'partCircle'. Oh well.
Barry