0

I am doing an eye-tracking experiment trying to find out the influence of two languages on the fixation proportions of participants on two different Areas of interest (AOIs), along the time.

My independent variables: Language (L1 vs. L2), AOI (AOI1 vs. AOI2), and time (divided into 50 time bins already). I want to plot a graph with four lines, each line stands for the fixation percentage of "L1 AOI1", "L1 AOI2", "L2 AOI1" and "L2 AOI2". An example of my data.frame is as follows:

Stimulus Bin Language  AOI     percentage
1         1     L1     AOI1      0.75
1         1     L1     AOI2      0.12
1         1     L2     AOI1      0.54
1         1     L2     AOI2      0.36
...     
10        1     L1     AOI1      0.85
10        1     L1     AOI2      0.10
10        1     L2     AOI1      0.60
10        1     L2     AOI2      0.23
...
10        7     L1     AOI1      0.64
10        7     L1     AOI2      0.14
10        7     L2     AOI1      0.66
10        7     L2     AOI2      0.21
...

I think I do not need to melt my data, right? because it is already in a long format.

I have draw two graphs with facet_wrap as follows, but how could I get ONE graph with all those information?

ggplot(data,aes(Bin, percentage, linetype = Language)) +`enter code here`
  facet_wrap(~ AOI)+
  stat_summary(fun.y = mean,geom = "line")+
  stat_summary(fun.data = mean_se,geom = "ribbon",
               color = NA, alpha = 0.3) +
  theme_bw(base_size = 10) +
  labs(x = "2000 ms since picture onset (50 time bins)", 
       y = "fixation proportion") +
  scale_linetype_manual(values = c("solid","dashed"))

Any ideas would be of great help to me.

Thanks!

markus
  • 25,843
  • 5
  • 39
  • 58
Jan.HD
  • 3
  • 3

1 Answers1

0

facet_wrap is not the function you need for that. Instead you can add color = AOI in the ggplot(aes()) in addition to linetype = Language. It will make different colors for OAI and different linetypes for Language, so 4 different lines on the same graph. This post may interest you : https://stackoverflow.com/a/3777592/10580543

tom
  • 725
  • 4
  • 17
  • Hi @tdel! Thanks for your help! I add color = AOI and it works well! I still got question. In my code, I have a code to visualize the standard error: stat_summary(fun.data = mean_se,geom = "ribbon", color = NA, alpha = 0.3). Now the range are all in the middle of the graph, but not along each lines. Do you have a idea to fix it? – Jan.HD Jul 02 '19 at 15:46
  • It seems that with my code above, r averaged the standard error of two AOIs of a language. So the ribbons are all around 50%. Is it possible to tell R to visualize the SE of two AOIs seperately? – Jan.HD Jul 02 '19 at 16:00
  • 1
    Could you add more code so I can reproduce the issue ? – tom Jul 02 '19 at 16:33
  • Hi @tdel. Thanks for still following this question! This is the code I use right now: ggplot(data,aes(Bin, percentage, color = AOI, linetype = Language)) + stat_summary(fun.y = mean,geom = "line")+ stat_summary(fun.data = mean_se,geom = "ribbon", color = NA, alpha = 0.3) + theme_bw(base_size = 10) + labs(x = "2000 ms since picture onset (50 time bins)", y = "fixation proportion") + scale_linetype_manual(values = c("solid","dashed")) – Jan.HD Jul 02 '19 at 21:32
  • It seems that the "mean_se" in the second "stat_summary" only refers to the variable "Language" but not "AOI" at the same time. I think I may need to change something here. What do you think? Thanks for your help! – Jan.HD Jul 02 '19 at 21:34
  • You may bypass the issue using ```geom_line``` and ```geom_ribbon()```. Check this post ; https://stackoverflow.com/questions/50223694/ggplot2-standard-error-ribbons-not-matching-the-plot-lines. I am sorry I am not so familiar with the mean_se function. – tom Jul 03 '19 at 08:02