0
votes

My dataframe looks like this

var1  var2  var3 var4 var5 var6 ..... var57
1     23    67   89   63   34   .....  90
2     34    43   43   23   23   .....  32
3     45    65   45   32   54   .....  43
4     45    32   18   61   87   .....  39

5     23    74   53   54   76   .....  54
6     21    65   34   34   12   .....  97
.     .      .    .    .    .   .....  .  
.     .      .    .    .    .   .....  .  
.     .      .    .    .    .   .....  .   
365    54     78   54  12    90  .....  53 

I used the following script to produce plots of var1 as my independent variable against all the variables (var2~ var1; var3 ~var1;var4~var1;var5~var1....var365 ~ var 1) (courtsey of Senor O):

pdf("Plots.pdf")
for(i in 2:ncol(df)) plot(df[,1], df[,i])
dev.off()

My issue is I want to insert, for each plot, a vertical line using the abline function whose position is different for all the plots. For example, for var2 ~ var1, the vertical line should be at 147, var 2 ~ var 1 the vertical line should be at 152.......var365 ~ var1 the vertical line should be at 160. Is there any way I can automate this in the previous script?

1
How do you determine the position of the vertical line?koekenbakker

1 Answers

0
votes

Try this:

offsets = c(147, 152, ...)
pdf("Plots.pdf")
for(i in 2:ncol(df)) {
  plot(df[,1], df[,i])
  abline(v=offsets[[i - 1]])
}
dev.off()