I am trying to plot in R my analyses, but in the plot I have overlapping lines.
How could I set an offset for the lines?
Thank you!
Here is my code and the plot:
mu <- 1.25e-8
gen <- 30
EA_S<-read.table("coal_output_E_S.final.txt", header=TRUE)
EA_WA<-read.table("coal_output_E_W.final.txt", header=TRUE)
S_CA<-read.table("cross_coal_S_CA.final.txt", header=TRUE)
S_WA<-read.table("cross_coal_S_WA.final.txt", header=TRUE)
WA_CA<-read.table("cross_coal_WA_CA.final.txt", header=TRUE)
EA_CA<-read.table("cross_coal_EA_CA.final.txt", header=TRUE)
plot(S_CA$left_time_boundary/mu*gen, 2 * S_CA$lambda_01 / (S_CA$lambda_00 + S_CA$lambda_11), xlim=c(1000,10000),ylim=c(0,1), type="n", xlab="Years ago", ylab="relative cross-coalescence rate")
lines(EA_S$left_time_boundary/mu*gen, 2 * EA_S$lambda_01 / (EA_S$lambda_00 + EA_S$lambda_11), type="s", col="red")
lines(S_CA$left_time_boundary/mu*gen, 2 * S_CA$lambda_01 / (S_CA$lambda_00 + S_CA$lambda_11), type="s", col="blue")
lines(S_WA$left_time_boundary/mu*gen, 2 * S_WA$lambda_01 / (S_WA$lambda_00 + S_WA$lambda_11), type="s", col="green")
lines(WA_CA$left_time_boundary/mu*gen, 2 * WA_CA$lambda_01 / (WA_CA$lambda_00 + WA_CA$lambda_11), type="s", col="grey")
lines(EA_CA$left_time_boundary/mu*gen, 2 * EA_CA$lambda_01 / (EA_CA$lambda_00 + EA_CA$lambda_11), type="s", col="orange")
lines(EA_WA$left_time_boundary/mu*gen, 2 * EA_WA$lambda_01 / (EA_WA$lambda_00 + EA_WA$lambda_11), type="s", col="violet")
legend("topright",legend=c("EA-S", "S-CA", "S-WA", "WA-CA", "EA-CA", "EA-WA"), col=c("red", "blue", "green", "grey", "orange", "violet"), lty=c(1,1))
Here is the part of two datasets, which overlap with lines on the plot:
time_index left_time_boundary right_time_boundary lambda_00 lambda_01 lambda_11
0 -0 1.58582e-06 3615.98 0.884757 1443.74
1 1.58582e-06 3.21283e-06 1578.55 1721.22 1863.89
2 3.21283e-06 4.88323e-06 2726.62 3580.91 4435.2
3 4.88323e-06 6.5994e-06 4147.57 4405.21 4662.84
4 6.5994e-06 8.36392e-06 6252.45 5971.77 5691.09
5 8.36392e-06 1.01796e-05 9308.97 8736.93 8164.9
6 1.01796e-05 1.20495e-05 11237.5 10557.5 9877.47
7 1.20495e-05 1.39769e-05 12046.9 11505.3 10963.7
8 1.39769e-05 1.59655e-05 12281.6 12053.4 11825.1
9 1.59655e-05 1.80194e-05 12763.3 12742.7 12722.1
10 1.80194e-05 2.01428e-05 11815.7 11691.6 11567.4
11 2.01428e-05 2.23408e-05 11815.7 11691.6 11567.4
12 2.23408e-05 2.46188e-05 10304.8 10106.4 9908.06
13 2.46188e-05 2.69827e-05 10304.8 10106.4 9908.06
14 2.69827e-05 2.94393e-05 8503.26 8475.02 8446.77
15 2.94393e-05 3.19963e-05 8503.26 8475.02 8446.77
And the second one:
0 -0 1.57981e-06 2025.99 0.829963 10270.7
1 1.57981e-06 3.20067e-06 2880.22 1958.46 1036.7
2 3.20067e-06 4.86475e-06 2912.59 2793.71 2674.84
3 4.86475e-06 6.57443e-06 3955.61 4183.41 4411.22
4 6.57443e-06 8.33227e-06 6294.89 6708.68 7122.47
5 8.33227e-06 1.01411e-05 9083.21 9611.25 10139.3
6 1.01411e-05 1.20039e-05 10572.2 11166.7 11761.2
7 1.20039e-05 1.3924e-05 11362.9 11718.9 12074.9
8 1.3924e-05 1.59051e-05 11910.6 11959.8 12008.9
9 1.59051e-05 1.79512e-05 12659.6 12459.8 12260
10 1.79512e-05 2.00666e-05 11849.3 11567.4 11285.6
11 2.00666e-05 2.22563e-05 11849.3 11567.4 11285.6
12 2.22563e-05 2.45256e-05 10413.3 10215.5 10017.8
13 2.45256e-05 2.68806e-05 10413.3 10215.5 10017.8
14 2.68806e-05 2.93279e-05 8619.84 8638.26 8656.68
15 2.93279e-05 3.18752e-05 8619.84 8638.26 8656.68