Here we’re going to think about some plotting exercises. You will need the following packages:

library(reshape2)
library(ggplot2)

We will be working with the simulated data that we put together while I was in Serbia- so lets load that in here:

SimulatedData <- read.csv("F:/Google Drive/Experiments/Collaborations/Stekic et al/Repo/Data/Simulated Training Results.csv")

First, I want you to do some plots and descriptive stats that tell me about the distribution of data in our various sets of data. You can get clues for how this should be done by taking a look at the examples in the Pejovic data analysis file (which can be found in this folder on Git)

In this first block, I want you to show me how to do some normality tests

library(moments)
library(nortest)
library(e1071)

Next, I’d like to see some graphical representations of the distributions

Now, I’d like to see you figure out how to produce the following graph: Hint, this makes use of ggplot and specifically facet_wrap This also makes use of the melt() command from Reshape

Okay, you might be thinking “Cmon Alan… really? So here is a start”

#ggplot(SimulatedData, aes(sample = RT.1, colour= XXX)) + 
  #SOMETHING that tells us what kind of plot we are making + (e.g. geom_line makes a line, geom_scatter makes a scatter)
  #ggtitle("qq Plots of Simulated Data by Condition") +
  #labs(x="", y="") +
  #theme(axis.title.y = element_text(size=12,  color="#666666")) +
  #theme(axis.text = element_text(size=8)) +
  #theme(plot.title = element_text(size=16, face="bold", hjust=0, color="#666666")) +
  #facet_wrap(SOMETHING)

You will find, when you produce this graph, that the facets are not in the right order by default - getting them to show up in the right order requires some wizardry

use https://stackoverflow.com/questions/14262497/fixing-the-order-of-facets-in-ggplot for guidance to how to get this to output correctly

Ultimately, I want you to output this graph

Congrats, you’ve made a pretty cool graph- it’s not an interesting one, because we know that all of our data is sampled from completely normal distributions - but you’ve done it.

Can you manage to do the same thing, but for actual response data?

Minimally, I’d like you to produce the following two graphs

So these are, again, pretty cool- but in this case, we’ve already plotted this data before (though not in this format)

Face_wrap is nice, but in this case there isn’t really a particularly good reason to use it - so lets think about a case where we want to plot many things on on graph where facets will be useful.

In this case, you’re going to produce a graph where all six of our sets of simulated data are presented in a single ggplot output, like this:

Here, you can have a final plot as inspiration- and in this case I’ll let you see the code itself as well:

Producing either of these graphs is fine- although obviusly the second one is prettier at lower resolution

MeltedCorrectnessData$Condition2 <- factor(MeltedCorrectnessData$Condition, 
                                  level = c("1", "2", "3A", "3B", "4", "5", "6A", "6B", "7", "8", "9", "10"),
                                  labels = c("Category Congruent", "Category Incongruent", "Category Conventional 1", "Category Conventional 2",
                                             "Item Congruent", "Item Incongruent", "Item Conventional 1", "Item Conventional 2",
                                             "Arbitrary Half-Half 1", "Arbitrary Half-Half 2", "Arbitrary- Fully", "No Label"))

ggplot(MeltedCorrectnessData, aes(x= Block, y= RespCorr, colour= Congruency)) + 
  geom_point(aes(shape = CatVsItem), alpha = 0.4, size = 0.4) +
  geom_smooth(aes(colour = Congruency, linetype = CatVsItem),size = 0.8, alpha = 0.4, se = F, method= 'loess', formula =  y~x)+
  ggtitle("Simulated Proportion Correct by Condition by Simulation") +
  labs(x="Block", y="Proportion Correct") +
  coord_cartesian(ylim = c(0, 1)) +
  theme(axis.title.y = element_text(size=12,  color="#666666")) +
  theme(axis.text = element_text(size=8)) +
  theme(plot.title = element_text(size=16, face="bold", hjust=0, color="#666666")) +
  facet_wrap(Condition2 ~ Simulation, ncol = 6) +
  theme(strip.text.x = element_text(size = 8, colour = "black"))

ggplot(MeltedCorrectnessData, aes(x= Block, y= RespCorr, colour= Congruency)) + 
  geom_point(aes(shape = CatVsItem), alpha = 0.4, size = 0.4) +
  geom_smooth(aes(colour = Congruency, linetype = CatVsItem),size = 0.5, alpha = 0.4, se = F, method= 'loess', formula =  y~x)+
  ggtitle("Simulated Proportion Correct by Condition by Simulation") +
  scale_y_continuous("Proportion Correct", breaks = c(0, 1), labels = c("0", "1"), limits = c(0, 1)) +
  scale_x_continuous("Block", breaks = c(1,9), labels = c("1","9"), limits = c(1, 9)) +
  #theme(axis.title.y = element_text(size=12,  color="#666666")) +
  theme(axis.text = element_text(size=8)) +
  theme(plot.title = element_text(size=16, face="bold", hjust=0, color="#666666")) +
  facet_grid(Condition2 ~ Simulation) +
  theme(strip.text.x = element_text(size = 8, colour = "black"),
        strip.text.y = element_text(size = 8, colour = "black", angle = 0),
        strip.background = element_rect(fill= "#FFFFFF")) 

Note that you won’t really be able to see this graph when it is output in the RMD document- you can thus find it in the folder where you can get a good luck at everything that is plotted.

Good luck! Let me know if you get stuck!