0

How would I create a circle with a grid inside it and then fill in cells that are occupied based on an X,Y coordinate system.

My circle looks like this (numbers are position numbers):

my grid

And I have set up my X,Y system with position 1 as -2,4.....

Thanks,

Alissa

Alissa R
  • 3
  • 5
  • This post (https://stackoverflow.com/questions/6862742/draw-a-circle-with-ggplot2) will help you draw a circle on an empty graph using ggplot. It's not clear to me how you want to fill the cells in, but i imagine drawing the circle is the hard part. – mmyoung77 Nov 10 '17 at 22:06
  • Thanks- I want to fill the cells in with dots in the middle of the cell (not on the x,y intercept). – Alissa R Nov 10 '17 at 22:10

1 Answers1

0
plot(5*c(1,0,-1,0), 5*c(0,1,0,-1) ,col="transparent")  # set coordinate range
abline(h=-5:5); abline(v=-5:5)  # the grid
polygon(  4.3*sin(seq(0,2*pi,length=100)), 
          4.3*cos(seq(0,2*pi,length=100)) )  # the circle
abline(h=0,v=0,lwd=2)  # the axes
 text( x=c( (1:4)-2.5,(1:6)-3.5, (1:8)-4.5, (1:8)-4.5, #offsets to center in cells
        (1:8)-4.5, (1:8)-4.5,  (1:6)-3.5, (1:4)-2.5 ),
   y=c( rep(4,4), rep(3,6), rep(2,8), rep(1,8), 
            rep(0,8), rep(-1,8), rep(-2,6), rep(-3,4) )-0.5, 
   labels=1:52)

enter image description here

Suppressing the axis labels, the axis ticks, and removing the "overhang" is a simple matter of supplying the correct graphics parameters (for xaxs, yaxs, xaxt, yaxt, xlab and ylab) to the plot function call. Perhaps:

 ..., , xaxs="i", yaxs="i", xaxt="n", yaxt="n", ylab="", xlab="")  

Which would produce this:

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • WOW. That is exactly what I needed. Thank you for your help- this worked perfectly!!! – Alissa R Nov 13 '17 at 18:15
  • Now I just need to plot my occupied cells on the figure but I think that making the actual circle was the difficult part. – Alissa R Nov 13 '17 at 18:16