根据遗传数据使用饼图创建地图

发布于 2025-01-12 20:22:29 字数 1350 浏览 4 评论 0原文

我正在进行群体遗传学研究并处理橡树物种的叶绿体数据。我进行了 DAPC,发现有 5 个叶绿体基因型簇。我想制作一张地图,根据我通过饼图或类似的东西采样的 26 个人口来显示每个人的比率。 我用以下列创建了一个 sf 对象:单个样本(Row.names 和 TreeNum)、它们所属的群体(代码)、它们的坐标(纬度、经度和几何=个体之间的平均值,以便给我一个单一的坐标来表示每个人口)和表示它们属于 5 个聚类中哪一个的因子值 (grp.grp)。

  <I<chr>>  <chr>   <chr>     <dbl>    <dbl> <fct>           <POINT [°]>
1 A01       A01     AZH       -123.     38.0 2       (-122.6256 37.9655)
2 A02       A02     AZH       -123.     38.0 4       (-122.6256 37.9655)
3 A04       A04     AZH       -123.     38.0 4       (-122.6256 37.9655)
4 A07       A07     AZH       -123.     38.0 2       (-122.6256 37.9655)
5 A08       A08     AZH       -123.     38.0 4       (-122.6256 37.9655)
6 A09       A09     AZH       -123.     38.0 2       (-122.6256 37.9655)

我已经能够使用 R 中的 tmap 包生成一个地图,该地图按颜色显示每个单独样本的因子值,但这些开始相互堆叠并且难以阅读。 我想生成一个带有饼图的地图,该饼图显示每个总体中因子值的比率,并记录该总体中的样本数量。有些群体有 10 个样本,其他群体只有 4 个样本,所以最好展示一下。 我不会将其用于出版物,只是为了探索数据。

我一直在考虑解决这个问题的方法是改变当前的 sf 对象并创建新的列,这些新列为我提供了我可以使用的每个因子值的频率百分比。如果这样做了,我将需要生成一个新的 sf 对象,该对象被修改为只为每个总体生成一行,然后生成描述我想要使用的值的列。还不清楚我如何将描述每个总体因子值百分比的每一列放入单个列中。 我觉得必须有一种更简单的方法来做到这一点。有人可以给一些好的建议吗?如果这是解决这个问题的最直接的方法,您将如何编码、格式化和创建这个 sf 对象? 另外,从那里,您建议如何构建这些映射的饼图?我在网上查看并发现了一些有用的帖子,但如何将 tmaps(我当前使用的包)与 ggplot & 结合起来? scatterpie 似乎不像其他示例那样直接处理我的数据。

任何帮助将不胜感激。谢谢!

I am doing a population genetics study and working with chloroplast data from an oak species. I have performed a DAPC and found that there are 5 clusters of chloroplast genotypes. I want to make a map that shows the ratios of each of these based on the 26 populations that I sampled via a pie chart or something similar.
I have made an sf object with the columns: individual samples(Row.names and TreeNum), the populations they belong to(Code), their coordinates(Lat, Long and geomentry = averaged among individuals to give me a single coordinate to represent each population) and a factor value that represents which of the 5 clusters they belong to(grp.grp).

  <I<chr>>  <chr>   <chr>     <dbl>    <dbl> <fct>           <POINT [°]>
1 A01       A01     AZH       -123.     38.0 2       (-122.6256 37.9655)
2 A02       A02     AZH       -123.     38.0 4       (-122.6256 37.9655)
3 A04       A04     AZH       -123.     38.0 4       (-122.6256 37.9655)
4 A07       A07     AZH       -123.     38.0 2       (-122.6256 37.9655)
5 A08       A08     AZH       -123.     38.0 4       (-122.6256 37.9655)
6 A09       A09     AZH       -123.     38.0 2       (-122.6256 37.9655)

I have been able to generate a map using the tmap package in R that shows each individual sample's factor value by color, but these begin to stack on top of each other and are hard to read.
I want to generate a map with a pie charts that shows the ratio of factor values within each population AND notes the number of samples from that population. Some populations have 10 samples, others only have 4, so it would be good to display this.
This isn't something that I am going to be using for a publication, just to explore the data.

How I have been thinking about solving this problem is to mutate the current sf object and create new columns that give me a percentages of the frequency of each factor value that I can use. If this was done though, I would then need to generate a new sf object that was modified to only produce a single row for each population and then columns that describe the values that I want to use. Its also unclear how I would get each column describing the percent of factor values per population into a single column.
I feel like there must be an easier way to do this. Can anyone give some good suggestions? If this is the most straight-forward way of working this out, how would you go about coding, formatting and creating this sf object?
Also, from there, how would you recommend building these mapped pie charts? I have looked online and found some useful posts but how to incorporate tmaps(the package I am currently using) with ggplot & scatterpie don't seem as straight forward with my data as the other examples.

Any help would be greatly appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文