如何在R中绘制一个带有点的圆? [英] How do I plot a circle with points inside it in R?

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

问题描述

我需要绘制一个以R中(0,0)为中心的圆.然后,我想绘制该圆中以半径和度指定的点.有人能为我指出正确的方向吗?

I need to plot a circle centered at (0,0) in R. Then I would like to plot points in that circle specified in radius and degrees. Could anyone point me in the right direction for this task?

推荐答案

在基本图形中:

r <- 3*runif(10)
degs <- 360*runif(10)

# First you want to convert the degrees to radians

theta <- 2*pi*degs/360

# Plot your points by converting to cartesian

plot(r*sin(theta),r*cos(theta),xlim=c(-max(r),max(r)),ylim=c(-max(r),max(r)))

# Add a circle around the points

polygon(max(r)*sin(seq(0,2*pi,length.out=100)),max(r)*cos(seq(0,2*pi,length.out=100)))

请注意,至少有一个点将在圆的边界上,因此,如果您不希望这样做,可以将max(r)陈述替换为1.1*max(r)

Note that at least one of the points will be on the border of the circle, so if you dont want this you would have replace of the max(r) statments with something like 1.1*max(r)

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

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