在 R 中的正方形内绘制一个圆 [英] plotting a circle inside a square in R

查看:54
本文介绍了在 R 中的正方形内绘制一个圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的插图,其中在正方形内绘制了一个圆圈.我使用了 grid 包中的 rect() 函数和 plotrix 包中的 draw.circle() 函数> 之前打包,所以我认为这很简单.但显然我错过了一些东西.

I am trying to make a simple illustration where a circle is plotted inside a square. I have used the rect() function from the grid package and the draw.circle() function from the plotrix package before so I thought this would be simple. But clearly I am missing something.

以下代码在我看来应该可以工作:

The following code seems to me like it should work:

require(plotrix)
require(grid)

plot(c(-1, 1), c(-1,1), type = "n")
rect( -.5, -.5, .5, .5) 
draw.circle( 0, 0, .5 )

但是我最终得到了这样的垂直维度上的圆圈:

however I end up with the circle lapping out of the square in the vertical dimension like this:

我到底错过了什么?

如果您有绘制圆形和正方形的更简单方法,我很想知道.但我也想知道为什么我上面的方法不起作用.

If you have a simpler way of plotting circles and squares, I'd love to know about it. But I'd also like to know why my method above does not work.

谢谢!

推荐答案

需要指定asp=1

require(plotrix)
require(grid)

plot(c(-1, 1), c(-1,1), type = "n", asp=1)
rect( -.5, -.5, .5, .5) 
draw.circle( 0, 0, .5 )

另见:绘制非相交圆这个也给我了!

这篇关于在 R 中的正方形内绘制一个圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆