简体   繁体   English

将样本大小数据添加到 R 中的饼图(mapplots 包)

[英]Adding sample size data to pie chart in R (mapplots package)

I have been able to plot several pie charts overtop a map, representing different populations.我已经能够在 map 上绘制几个饼图,代表不同的人群。 However, what I would like to do is somehow represent the sample size for each of the pie charts, as its differs between population.但是,我想做的是以某种方式表示每个饼图的样本大小,因为它在人群之间有所不同。 I have a loop to add each population present in the dataset as a pie chart:我有一个循环将数据集中存在的每个人口添加为饼图:

map("worldHires", xlim=c(-140, -110), ylim=c(48, 64), col="lightgray", fill=TRUE)
points(x=-120.43,y=50.34, col="black", pch=19)
segments(x0=dataframe$Long, y0=dataframe$Lat, x1=dataframe$Long2, y1=dataframe$Lat2, col="black")
add.pie(z=c(2, 5, 6),x=-122.43,y=52.34,labels="",radius = 1)
for(i in 1:nrow(dataframe))
{
  add.pie(as.integer(dataframe[i,c("Cat1","Cat2", "Cat3")]*100),
          x=dataframe$Long2[i],y=dataframe$Lat2[i],labels="",radius = 0.08,
          col=c("red","blue", "green"))
}
title(ylab="Latitude")
title(xlab="Longitude")
box(which="plot")

I would like to add the sample size data (dataframe$n) somehow.我想以某种方式添加样本大小数据(dataframe$n)。 I've seen examples of scaled radius pie charts, which could work here, or even just adding the sample size above the pie chart.我已经看到了缩放半径饼图的示例,它可以在这里工作,甚至只是在饼图上方添加样本大小。 To get the sample size above the pie chart I tried adding 'main=dataframe$n' between labels and radius in the add.pie portion of the code, but this did not work.为了获得饼图上方的样本大小,我尝试在代码的 add.pie 部分的标签和半径之间添加“main=dataframe$n”,但这不起作用。 Does anyone have any ideas on how to add this to my script?有人对如何将其添加到我的脚本有任何想法吗? Thank you.谢谢你。

The size of each pie is plotted according each value in your dataframe.每个饼的大小是根据 dataframe 中的每个值绘制的。 The good dataframe for this has a stations as rows and the class type are columns好的 dataframe 有一个站作为行,class 类型是列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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