5.15 Reformatting AFs for plotting

Because ggplot requires its input data to be formatted as a table, we have to convert freq_vector into some form of table (ex: a tibble or dataframe).

sim_results <- tibble(af = freq_vector)
head(sim_results)
## # A tibble: 6 × 1
##      af
##   <dbl>
## 1  0.5 
## 2  0.52
## 3  0.64
## 4  0.63
## 5  0.65
## 6  0.63

This table contains the information that we want on the plot’s y axis. We can now add in a column containing the plot’s x axis data, which is the generation that each AF value corresponds to.

sim_results <- tibble(af = freq_vector,
                      gen = 1:21)
head(sim_results)
## # A tibble: 6 × 2
##      af   gen
##   <dbl> <int>
## 1  0.5      1
## 2  0.52     2
## 3  0.64     3
## 4  0.63     4
## 5  0.65     5
## 6  0.63     6

Why does the gens column range from 1 to 21 (instead of 1 to 20)?

We add our starting allele frequency to freq_vector, and then simulate for 20 generations. This means that we end up with 21 AFs in our vector.