add_start_points: Add rows to a population dataframe to ensure genotype...

View source: R/MullerPlot.R

add_start_pointsR Documentation

Add rows to a population dataframe to ensure genotype starting points are plotted correctly

Description

The function 1) identifies when genotypes first have non-zero populations; 2) copies all the rows of data for these time points; 3) modifies the copied rows by decreasing Generation and setting Population of the emerging genotypes to be close to zero; and then 4) adds the modified rows to the dataframe. This ensures that ggplot plots genotypes arising at the correct time points.

Usage

add_start_points(pop_df, start_positions = 0.5)

Arguments

pop_df

Dataframe with column names "Identity", "Population", and either "Generation" or "Time"

start_positions

Numeric value between 0 and 1 that determines the times at which genotypes are assumed to have arisen (see examples)

Details

By default, the function assumes that each genotype arose half way between the latest time at which its population is zero and the earliest time at which its population is greater than zero. You can override this assumption using the start_positions parameter. If start_positions = 0 (respetively 1) then each genotype is assumed to have arisen at the earliest (respectively latest) time compatible with the data. Intermediate values are also permitted.

Value

The input Dataframe with additional rows.

Author(s)

Rob Noble, robjohnnoble@gmail.com

Examples

pop1 <- data.frame(Generation = rep(1:5, each = 4), Identity = rep(1:4, 5), 
                   Population = c(1,0,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1))
add_start_points(pop1)

# to see the effect of changing start_positions, compare the Generation columns:
add_start_points(pop1, 0)
add_start_points(pop1, 1)


ggmuller documentation built on Feb. 16, 2023, 7:42 p.m.