简体   繁体   中英

Plotting symbols in R as Pie Charts of the Weights

Consider this toy example in 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),"/")

where each point has probabilities associated with being in 3 groups. For example, the first observation has

     [,1]       [,2]      [,3]
 [1,] 0.2507483 0.32198731 0.4272644

0.25 probability of being in group 1, 0.32 of being in group 2 and 0.43 of being in group 3. How can I make a plotting symbol for each point to look like a mini pie chart that will colour the pie chart accordingly? For example, for the first point, the plotting symbol would look like this

pie(weights[1,],labels=NA)

在此处输入图片说明

Using 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"))
}

Which produces:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM