【问题标题】:How do I create a circle with a grid inside and mark occupied cells in R?如何创建一个内部有网格的圆圈并在 R 中标记占用的单元格?
【发布时间】:2018-04-24 04:54:30
【问题描述】:

如何创建一个内部带有网格的圆圈,然后填充基于 X、Y 坐标系的单元格。

我的圈子是这样的(数字是位置数字):

我已经将我的 X,Y 系统设置为 位置 1 为 -2,4.....

谢谢,

艾丽莎

【问题讨论】:

标签: r coordinates spatial geometry


【解决方案1】:
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)

抑制轴标签、轴刻度和移除“悬垂”只是为plot 函数调用提供正确的图形参数(对于xaxs、yaxs、xaxt、yaxt、xlab 和ylab)很简单。也许:

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

这会产生这个:

【讨论】:

  • 哇。这正是我所需要的。感谢您的帮助-效果很好!!!
  • 现在我只需要在图中绘制我占用的单元格,但我认为制作实际的圆圈是困难的部分。
猜你喜欢
  • 2014-06-19
  • 2019-12-04
  • 1970-01-01
  • 2010-11-04
  • 2017-07-22
  • 1970-01-01
  • 2019-07-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多