 <p>This is because you are effectively only using <code>data1</code>.</p> <p>The first loop can be expanded to</p> <pre><code>data1 = read.table('data1_lambda.dat', ...) data2 = read.table('data2_lambda.dat', ...) data3 = read.table('data3_lambda.dat', ...) </code></pre> <p>whereas your second loop is a bit buggy and the cause of the fault. If I expand the loop, what happens is:</p> <pre><code>plot(data.frame(data1[1], data1[2]), ...) lines(data.frame('data2[1]', 'data2[2]', ...) lines(data.frame('data3[1]', 'data3[2]', ...) </code></pre> <p>i.e. what you think is fetching <code>data2</code> and <code>data3</code>, you are really only using the strings <code>'data2'</code> and <code>'data3'</code> (note the quotation marks).</p> <p>Without assuming too much of your data and restructuring you entire code, this should do the trick (for the second loop). Since you only have three data-files, looping seems a bit extensive contra the problems they are introducing.</p> <pre><code>plot(data.frame(data1[1], data1[2]), xlim=c(-0.2, -7), ylim=c(0.31, 0.35), yaxt="n", type="l", xlab="", ylab="",lty="solid", col="red2", lwd=4, axes=TRUE) lines(data.frame(data2[1], data2[2]) ,lty="twodash", col="deepskyblue4", lwd=4) lines(data.frame(data3[1], data3[2]) ,lty="twodash", col="deepskyblue4", lwd=4) </code></pre> <p>If you insist on looping, we could do:</p> <pre><code>for(i in 1:3){ if(i==1){ plot(data.frame(data1[1], data1[2]), xlim=c(-0.2, -7), ylim=c(0.31, 0.35), yaxt="n", type="l", xlab="", ylab="",lty="solid", col="red2", lwd=4, axes=TRUE) } else { dat &lt;- get(paste('data', i, sep='')) lines(data.frame(dat[1], dat[2]) ,lty="twodash", col="deepskyblue4", lwd=4) } } </code></pre> <p>To further comment your code, in your <code>read.table</code> call, you have two nested <code>paste</code> calls, which in this case is unnecessary.</p> <p>paste(paste("data", i, sep=""),"_lambda.dat",sep="") # could be done with paste(paste("data", i, "_lambda.dat",sep="")</p>