考慮 R 中的這個玩具示例
x<-seq(0,1,length.out=10)
y<-sin(x)
plot(x,y)
set.seed(10)
weights <- matrix(runif(30),ncol=3)
weights <- sweep(weights,1,apply(weights,1,sum),"/")
其中每個點都有與屬于 3 個組相關的概率。例如,第一個觀察有
[,1] [,2] [,3]
[1,] 0.2507483 0.32198731 0.4272644
第 1 組的概率為 0.25,第 2 組的概率為 0.32,第 3 組的概率為 0.43。如何使每個點的繪圖符號看起來像一個迷你餅圖,從而相應地為餅圖著色?例如,對于第一點,繪圖符號將如下所示
pie(weights[1,],labels=NA)

uj5u.com熱心網友回復:
使用plotrix:
plot(-0.1:1, -0.1:1, "n")
for (i in 1:length(x)) {
floating.pie(x[i], y[i], weights[i,], radius=0.05, col = c("#ffffff", "#d3d3d3", "#add8e6"))
}
其中產生:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/340020.html
