6

I have drawn a (netball) court in R using ggplot2 and the following code:

require(ggplot2)
ggplot(Coords, aes(X,Y, colour=Position)) + 
geom_point() + 
coord_equal() + theme(plot.background = element_rect(fill = 'grey')) +
geom_path(data=NetballCourt, aes(X,Y), colour="black", size=1)`<br><br>

The sidelines plus transverse lines of the court are fine and these are contained in a data.frame that I have named "NetballCourt" with player movement "Coords" categorised according to individual position.

How do I draw a half circle, with a radius of 4.9 meters, at opposing ends of the court? For those unfamiliar with netball, the court dimensions are here... http://netball.com.au/our-game/court-venue-specifications/

user2716568
  • 1,866
  • 3
  • 23
  • 38
  • 1
    Here's a [SO answer](http://stackoverflow.com/questions/6862742/draw-a-circle-with-ggplot2) that shows how to draw a circle with `ggplot2`. You could adapt it to draw half circles. For a related approach, see [Hadley's answer](https://groups.google.com/forum/#!topic/ggplot2/f0I4tWWOhbs) to a question in the `ggplot2` Google group. – eipi10 Jan 28 '15 at 06:12
  • 1
    Another [useful answer](http://stackoverflow.com/questions/12794596/how-fill-part-of-a-circle-using-ggplot2). – tonytonov Jan 28 '15 at 07:50

1 Answers1

7

Thank you for the links, @eipi10 and @tonytonov.

I employed the following circle function:

circleFun <- function(center=c(0,0), diameter=1, npoints=100, start=0, end=2)
{
  tt <- seq(start*pi, end*pi, length.out=npoints)
  data.frame(x = center[1] + diameter / 2 * cos(tt), 
             y = center[2] + diameter / 2 * sin(tt))
}

I then included the specifics of the netball court, given the center of a full circle would be (0,7.625) and a diameter of 9.8

 dat <- circleFun(c(0,7.625), 9.8, start=1.5, end=2.5)

I then plotted this in R before adding the X and Y coordinates to my existing data.frame named "NetballCourt"

ggplot(dat,aes(x,y)) + 
geom_polygon(color="black") + 
ggtitle("half circle") +
coord_equal()
tonytonov
  • 25,060
  • 16
  • 82
  • 98
user2716568
  • 1,866
  • 3
  • 23
  • 38
  • For other start and end coordinates (which is what I wanted). so this draws the top half of a circle. `ggplot()+ geom_polygon(data=dat,aes(x=x,y=y),color='black',fill=NA)` – Jack Armstrong Nov 23 '18 at 13:20