绘制不同大小和位置的多个饼图
我想做一个多个馅饼。
df <- read.table(text="Position Depth Group Value
A 50 G1 30
A 50 G2 60
A 50 G3 10
A 200 G1 10
A 200 G2 10
A 200 G3 30
B 50 G1 24
B 50 G2 48
B 50 G3 8
B 100 G1 8
B 100 G2 8
B 100 G3 24
C 100 G1 36
C 100 G2 72
C 100 G3 12
C 600 G1 12
C 600 G2 12
C 600 G3 36",
header=TRUE)
位置:不同的采样站点;
深度:抽水深度;
组:三种不同的动物;
价值:动物的计数。
I would like to make a multiple pie plot.
df <- read.table(text="Position Depth Group Value
A 50 G1 30
A 50 G2 60
A 50 G3 10
A 200 G1 10
A 200 G2 10
A 200 G3 30
B 50 G1 24
B 50 G2 48
B 50 G3 8
B 100 G1 8
B 100 G2 8
B 100 G3 24
C 100 G1 36
C 100 G2 72
C 100 G3 12
C 600 G1 12
C 600 G2 12
C 600 G3 36",
header=TRUE)
Position: the different sampling site;
Depth: the sampling water depth;
Group: three different animals;
Value: the count of animals.
I'd like to make the figure like:
the size of pie:total count of Group(G1+G2+G3);
pie composition:Group(G1%, G2%, G3%)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现所需结果的一种选项是通过
scatspie :: geom_scatterpie
,它需要一些数据争吵。首先,您必须将分类位置
列转换为数字。其次,我们必须将数字位置
转换为与depth
的比例。第三,我们必须将value
列重命名为value
(GEOM_SCATTERPIE
要求使用长格式工作的数据)。最后,我选择了半径,使得馅饼区域反映了值的总和。根据您的输出格式,您可能必须对半径进行一些重新缩放,例如乘以3。img src =“ https://i.sstatic.net/rus7g.png”
< /strong>
One option to achieve your desired result would be via the
scatterpie::geom_scatterpie
which however requires some data wrangling. First you have to convert your categoricalPosition
column to a numeric. Second we have to transform the numericPosition
to the same scale asDepth
. Third, we have to rename theValue
column tovalue
(geom_scatterpie
demands that in case of working with data in long format). Finally I have chosen the radius such that the pie area reflects the sum of values. Depending on your output format you probably have to do some rescaling of the radius, e.g. multiplied by 3.DATA