Occassionally I do something other than playing with EEG data. R can also handle a lot of spatial data - in other words, you can create nice maps. There’s the small matter of an election coming up next month which is probably our last chance of avoiding a disastrous Brexit.
I decided to try out some of R’s mapping functions and packages to see if I could come up with any useful graphics of the sort you usually see: maps showing turn-out, who won each constituency, things like that.
As mentioned in my last post, an issue doing EEG analysis in R at the moment is that there’s a distinct lack of tools in R for a lot of the typical processing steps. In the past I’ve done a lot of processing in Matlab (specifically with EEGLAB and Fieldtrip) and shifted things over to R for statistics. But all is not lost. For example, with the following code, I can run a bunch of preprocessing, including automatic artefact rejection, and have nice ERPs in R in the blink of an eye!
An issue doing EEG analysis in R at the moment is that the tools just don’t exist to do a lot of the typical processing steps. It’s an extraordinarily complicated thing to produce working packages that cover even a few of the possible ways to analyse EEG data. The makers of tools like EEGLAB, Fieldtrip, and MNE have been doing it a long time, and not on their own. Essentially, there just isn’t a big community of EEG R users to develop and support dedicated packages at the moment.
In my previous post on plotting topographies in R, ERP Visualization: Creating topographical scalp maps: part 1, I was aiming for maximum comparability with EEGLAB defaults. That meant I used the ‘jet’ colour map, which is what I’m most used to using. You may have noticed that there was no default jet colour map - I had to define one manually. While jet produces nice, punchy looking images, there are a heap of problems associated with it.
As well as ERPs or time-frequency plots from individual channels, it’s always useful to see topographical maps of our data. It’s a nice way to see what’s going on across the whole head, showing us whether effects are broadly or narrowly distributed across the whole scalp. So now I’m going to show you how to do topographical plots in R.
I want to first of all thank alexforrance and Harold Cavendish over on Stack Overflow for being the source of much of the code I’ve adapted here.
In an earlier post I took a look at visualizing ERPs from two conditions at a single electrode. This time I’m going to look at three conditions. As in the previous post, I’ll assume a basic familiarity with ERPs.
First I’ll load in the full dataset, which contains ERPs for all conditions for all subjects, and whip it into shape.
library(ggplot2) library(tidyverse) library(afex) library(Rmisc) library(magrittr) levCatGAall <- read_csv( "https://raw.githubusercontent.com/craddm/ExploringERPs/master/levCatGAall.csv", col_names = c("Object.
Shiny app updated! In my last post unleashed the Shiny app I’d knocked up in a few hours to do some basic display of different confidence interval types and difference waves. I’ve been hacking away at it on and off and I’ve now added some exciting new features!
You can now try loading up your own data. You’ll need a .csv file with the following structure:
No header Comma-separated values Each row should be one time-point, one subject, columns should be “condition1”, “condition2”, “Time”, “Subject” Here’s the first few lines of the example data I include (note this is already after import, so it’s stripped the commas between values).
Shiny app In an unusual fit of enthusiasm, I decided to have to go at writing a little app in Shiny, a simple programming framework to make web-based apps using R. So, as usual, all programmed using RStudio, the devs who also make Shiny and various fantastic R packages such as dplyr and ggplot2.
It turned out to be pretty simple. I’m planning to add various additional functions as I get time to work on my blog posts, like allowing people to use their own data, for example.