lines() function when plotting trajectories

I have the following line of code:

plot.replicates(numrep=19,pstart=0.5,ngen=200,wAA=1, N=100, wAa=0.94,waa=0.97)

How would I be able to use the lines() function in this to show red lines on the plot for the fitness values? (WAA=1 and waa=0.97)?

As context this is the part of my workbook that I'm working from:

Type the command set.seed(49) and then use plot.replicates() to plot 19 trajectories for gene frequencies under the following scenario, running for 200 generations: population size 20; wAA=1, wAa = 0.94, waa = 0.97. The values in pstart vary from 0.05 to 0.95 in steps of 0.05. In addition, using the lines() function, for each starting frequency superimpose the deterministic trajectory for the same fitness values, colouring the lines red, with a double-width

Any help with this would be greatly appreciated, thank you.

plot.replicates comes from this function:

> plot.replicates = function(numrep,pstart,ngen,N,wAA,wAa,waa)
> #Function plot.replicates takes number of replicates, numrep; starting frequency, pstart; 
> #number of generations, ngen;Population size, N; fitnesses wAA, wAa, waa
> #makes a plot of trajectories
> #pstart may be a vector of length equal to numrep, in which case each trajectory will start 
> #with a frequency given in the pstart vector. Alternatively it may be a scalar, and then, if 
> #numrep is greater than 1, each trajectory will have the same starting frequency given by pstart.
> {
> 	if(numrep < 1){
> 		return("no replicates requested")
> 	}
> 	if(numrep > 1 && length(pstart) > 1 && length(pstart) != numrep){
> 		return("length of pstart must be either 1 or equal to the number of replicates requested")
> 	}
> 	if(numrep > 1 && length(pstart) == 1)pstart = rep(pstart,numrep)
> 	traj1 = make.trajectory(pstart[1],ngen,N,wAA,wAa,waa)
> 	plot(c(0:ngen),traj1,type="l",ylim=c(0,1),ylab="Frequency A",xlab="Generations")
> 	if(numrep == 1)return(paste(numrep,"replicates plotted"))
> 	for(j in 2:numrep){
> 		traj1 = make.trajectory(pstart[j],ngen,N,wAA,wAa,waa)
> 		lines(c(0:ngen),traj1)
> 	}
> 	return(paste(numrep,"replicates plotted"))
> }

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.