First, I want to clarify this is a very basic question. I'm new using R (and programming in general).

I have a data.frame with 3 columns:

block, average condition 1, average condition 2.

The blocks run from 1 to 9 and the average are response times averaged across subjects. What I want to do is to plot both averages, one for each condition, while having in the x axis the progression of blocks. Therefore, I would expect to have one line for each condition running above the x axis.

My question is what plot function should I use. I've tried with nearly everyone but what I thought would serve (simply plotting a vector with two columns as entry, against the block column) doesn't work, it gives the error:

 'x' and 'y' lengths differ

So I thought I should first plot only one condition and then somehow add the other line with a second command. I successfully plotted one condition as I wanted to:


So here I'm choosing the 3rd and 2nd columns to do the plotting, but what I want is to have two columns running parallel, each one with different colors.

I tried abline, using the other columns I haven't plotted yet as an argument, but I get the "invalid a=, b= specification"

Any suggestions are very welcome. Any other information I missed you can always ask.





would suffice... I guess

| cite | improve this answer | |
  • $\begingroup$ Thanks for your answer. Indeed the lines() function worked for me, though in a slightly different way. First I created my plot with column 1(y axis) and 3 (x axis): plot(meanrts2[,3],meanrts2[,1],ylab="RT",xlab="block",type="l") And then I just added the 2nd colum of my meanrts2 data.frame with this: lines(meanrts2[,2]) And I got the plot I wanted with the two lines stemming from the y axis and going across the x axis. $\endgroup$ – HernanLG May 9 '12 at 18:19
  • $\begingroup$ Seems like a good question and a good answer. I'm just confused because I've seen questions closed because they dealt only with how to program software and involved no statistical content. $\endgroup$ – rolando2 May 9 '12 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.