如何在R中生成点?

德米特里

我需要在 R 中生成点。我想得到这个例子中的情节:

想要的情节

我的主要任务:生成一个由 3 个集群组成的 2D 数据集,每个集群都沿着一个轴强烈拉伸。

我也有代码示例:

x <- rbind(matrix(rnorm(100, mean=0.2, sd=0.1), ncol=2), matrix(rnorm(100, mean=0.2, sd=0.1), ncol=2))
plot(x)

我想我应该更改参数,但我不知道如何更改。

罗米尔·洛达亚

我试过这种方法,看看它,如果有帮助的话。

# Creating 3 uniform data distributions 
a = matrix(runif(100, 0, 5), ncol=2)   
b = matrix(runif(100, 10, 15), ncol=2) 
c = matrix(runif(100, 10, 15), ncol=2) 

b[,1] = b[,1] - 10 # removing 10 units from x aixs
c[,2] = c[,2] - 10 # removing 10 units from y aixs

x <- rbind(a,b,c)  # binding rowise
plot(x)            # plot

输出: 方法 1 的输出

# Creating 3 uniform data distributions 
a = matrix(runif(100, 2, 4), ncol=2)   
b = matrix(runif(100, 1, 5), ncol=2) 
c = matrix(runif(100, 1, 5), ncol=2) 

b[,1] = b[,1] /5 # scaling x axis by 5 units
c[,2] = c[,2] /5 # scaling y axis by 5 units

x <- rbind(a,b,c)  # binding rowise
plot(x)            # plot

输出: 方法 2 的输出

另一种方法

# Creating normal distribution over X axis and uniform distribution over Y axis
a = cbind(rnorm(100, mean=3, sd=1),
        runif(100, 0, 1))

# Creating uniform distribution over X axis and normal distribution over Y axis
b = cbind(runif(100, 0, 1),
        rnorm(100, mean=3, sd=1))

# Creating normal distribution over both axis ranging from 2-4
c = matrix(runif(100, 2, 4), ncol=2)   

# binding row wise 300 samples 100 from each cluster and plotting
plot(rbind(a, b, c))

输出: 方法 3 的输出

希望有帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章