2
votes

Hello (from an R novice),

I'm running simulations with a neural network model of word recognition. The model essentially has detectors for each word in its lexicon at multiple temporal alignments (e.g., there are actually 67 detectors for 'dog', aligned at successive time points). So the output from a simulation is a file with the activations of every word detector at every time step of the simulation. So if the simulation is run for 100 cycles, the file would have 100 time-stamped activation records for all 67 dog units, and the same for every other word in the lexicon (e.g., 100 x Words x 67 datapoints). I have a run a simulation with every word in the lexicon, and now I want to use facet_wrap to make one plot for each simulation, plotting the over-time activations of the 10 most activated words.

I've figured out to convert that output to a time X detector matrix and then I sort that matrix by the peak activation of each column. I then remove everything but the top 10 columns. For a single simulation of a word like club, I wind up with data that looks like this (just showing the head of the output for just 4 words:

> head(traceOut.top[,c(1,2,3,4,12)])
  time kl^b.s3 kl^b.s4 klu.s3 Target
1    0   -0.01   -0.01  -0.01   kl^b
2    1   -0.01   -0.01  -0.01   kl^b
3    2   -0.01   -0.01  -0.01   kl^b
4    3   -0.01   -0.01  -0.01   kl^b
5    4   -0.01   -0.01  -0.01   kl^b
6    5   -0.01   -0.01  -0.01   kl^b

The column names indicate word detect + alignment. "kl^b.s3" indicates the detector for "club" (kl^b) at slice 3 (activations start changing after a couple dozen time steps). The Target column indicates what input has been given to the model.

I then melt the data:

> traceOut.m2 <-melt(as.data.frame(traceOut.top),id.vars=c("time","Target"),variable.name="Word")

> head(traceOut.m2)
  time Target    Word Activation
1     0   kl^b kl^b.s3      -0.01
2     1   kl^b kl^b.s3      -0.01
3     2   kl^b kl^b.s3      -0.01
4     3   kl^b kl^b.s3      -0.01
5     4   kl^b kl^b.s3      -0.01
6     5   kl^b kl^b.s3      -0.01

and rbind it to a data.frame called traceOut.m2.all that eventually has this kind of output for every target.

Then I try to use ggplot facet_wrap to make a plot for every word:

ggplot(traceOut.m2.all, aes(time,Activation,color=Word, shape=Word) ) + 
  facet_wrap(~ Target) +   
  geom_line(aes(label=Word))

The problem is that the top 10 word detectors are different for each word. I would like each plot to have a legend including only its top 10 list. Instead, a single legend with all the word detectors that occur in any plot is created. I do really need the specific column names in each plot, so I can't just change the column names to things like 1,2,3..10. Does anyone know of a way of doing this?

Thanks,

jim

1

1 Answers

0
votes

Okay, I gave up on this -- I don't think it's possible. Instead, as I read each file, I create a ggplot object with item-specific legend, save it to a list, and then create a multipanel plot after reading all files.

E.g.:

plotList[[length(plotList) + 1]]  <- ggplot(traceOut.m2, aes(time, Activation, color=Word) + geom_line(aes(label=Word))