1 year ago
#272651
Christopher McCarron
Creating maps with pie charts from genetic data
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!
r
tidyverse
tmap
genetics
scatterpie
0 Answers
Your Answer