A package to visualize ERPs in R
You have exported your preprocessed ERP data and loaded them into R in order to run your statistics? Why not plot your data in the same environment and take advantage of R high plotting capabilities?
The package is still under development to make it more flexible and compatible with more data formats.
Some new options will be available by the end of May 2021. To support these new options, some arguments will have a new names and new arguments have been created
We are also working on an interactive version of ERPscope for a release during the summer!
To install ERPscope, install the devtools package if you don't already have it (https://www.rdocumentation.org/packages/devtools)
install.packages("devtools")
Run the following command to install from the github repository
devtools::install_github("aherbay/erpscope")
.libPaths()
) detach("package:erpscope", unload=TRUE) #if ERPscope is loaded in your session
devtools::install_github("aherbay/erpscope") # update
library(erpscope) # loading again
Your dataframe should have: one column named Voltage (numeric) one column named Subject (factor) one column named Time (integer) one column named Electrode (factor) * one column for the conditionToPlot argument with the variable and levels to plot (factor)
plot_erp( data = relpriming,
conditionToPlot = Pair.Type,
electrodes_list = c("F3", "Fz", "F4","C3", "Cz","C4", "P3", "Pz", "P4"),
output_type = "pdf",
color_palette = c("#4DAF4A","#EA2721","#000000") ,
custom_labels = list(list(-450,-250,"Prime"),list(0,200,"Target")),
show_conf_interval = FALSE,
baseline = c(-500,-300),
adjusted_baseline = FALSE,
time_labels_interval = 200,
plotname = 'auto',
show_check_message = FALSE,
labels_vertical_position = 'auto',
labels_height = 'auto',
vary ="Voltage"
)
plot_erp( data = relpriming,
conditionToPlot = Pair.Type,
electrodes_list = c("F3", "Fz", "F4","C3", "Cz","C4", "P3", "Pz", "P4"),
color_palette = c("#4DAF4A","#EA2721","#000000") ,
custom_labels = list(list(-450,-250,"Prime"),list(0,200,"Target")),
baseline = c(-500,-300),
)
To show confidence interval ribbons, just set the argument show_conf_interval to TRUE as below:
plot_erp( data = relpriming,
conditionToPlot = Pair.Type,
electrodes_list = c("F3", "Fz", "F4","C3", "Cz","C4", "P3", "Pz", "P4"),
color_palette = c("#4DAF4A","#EA2721","#000000") ,
custom_labels = list(list(-450,-250,"Prime"),list(0,200,"Target")),
baseline = c(-500,-300),
show_conf_interval = FALSE
)
For now it is a mandatory argument. Display a red rectangle from the beginning to the end of the baseline time window.
You can adjust the ERPs to the baseline provided in the argument baseline by setting the argument adjusted_baseline to TRUE
You can add custom labels for stimuli appearing, or specific time window. It appears a vertical dotted line at start time with a grey rectangle with the label on the top of the plot.
To add a label you need to add a list to the custom_labels argument (which is a list of lists, by default an empty list).
The list defining a label has the structure : list(start_time, end_time, label). For example, to add a label displaying the word Prime between -450 ms and -250 ms, you would have : custom_labels = list( list(-450,-250,"Prime") )
The position of label is automatic by default but it can be adjusted to your need by changing the argument labels_vertical_position to the voltage you want the label to be centered on and the argument labels_height if you also want to change it's height (again in mV)
By default, the file is exported to a PDF file. It is aslo possible to export it to png, jpeg, pdf, png, svg by changing the argument output_type to "png" for example.
By default, the plot name is automatic. But it can be customized by changing the argument plotname
By default, only the ERPs are displayed. But it is possible to add the 95% confidence intervals for each condition by setting the argument show_conf_interval to FALSE.
By default there are 9 colors used to display ERPs : "#4DAF4A" (green), "#EA2721" (red), "#377EB8" (blue), "#FF7F00" (orange), "#984EA3" (purple), "#000000" (black), "#5c5c5c" (grey), "#945D25" (brown),"#FF748C" (pink), "#2E692C" (dark green).
To change the order of colors or to change them entirely, you can change the argument color_palette. For example, to put the colors red, blue, purple for 3 ERP lines color_palette = c("#EA2721","#377EB8","#984EA3")
. You can also use default values from R for example: c("blue","red","black")
.
line_thickness = 0.75 by default
background = "grid" , "white" , "dark"
plot_difference( data = relpriming,
conditionToPlot = Pair.Type,
levelA = Unrelated ,
levelB = Consistent,
electrodes_to_display = c("F3", "Fz", "F4","C3", "Cz","C4", "P3", "Pz", "P4"),
topoplots_time_windows = list(c(-250,-150),c(-150,50),c(50,200),c(200,300),c(300,500),c(500,700),c(700,900)),
baseline= c(-500,-200))
plot_difference( data = relpriming,
conditionToPlot = Pair.Type,
levelA = Unrelated ,
levelB = Consistent,
output_type ='pdf',
ant_levels= Anteriority.Levels,
med_levels= Mediality.Levels,
vary= Voltage,
group_var = Subject,
show_group_obs = TRUE ,
labels_vertical_position = 'auto',
labels_height = 'auto',
baseline= c(-500,-200),
topoplots_time_windows = list(c(-250,-150),c(-150,50),c(50,200),c(200,300),c(300,500),c(500,700),c(700,900)),
topoplots_scale = c(-2,2),
time_labels_interval = 200,
custom_labels = list(list(-450,-250,"Prime"),list(0,200,"Target")),
electrodes_to_display = c("F3", "Fz", "F4","C3", "Cz","C4", "P3", "Pz", "P4"),
plotname = 'auto'
)
You can display Subject data in light grey with show_group_obs = TRUE
plot_difference( data = relpriming,
conditionToPlot = Pair.Type,
levelA = Unrelated ,
levelB = Consistent,
output_type ='pdf',
ant_levels= Anteriority.Levels,
med_levels= Mediality.Levels,
vary= Voltage,
group_var = Subject,
show_group_obs = TRUE ,
labels_vertical_position = 'auto',
labels_height = 'auto',
baseline= c(-500,-200),
topoplots_time_windows = list(c(-250,-150),c(-150,50),c(50,200),c(200,300),c(300,500),c(500,700),c(700,900)),
topoplots_scale = c(-2,2),
time_labels_interval = 200,
custom_labels = list(list(-450,-250,"Prime"),list(0,200,"Target")),
plotname = 'auto'
)
Instead of displaying difference on 9 specific electrodes you can display it on 9 Regions of Interest To do so, just remove the line, electrodes_to_display or put it electrodes_to_display = c()
plot_difference( data = relpriming,
conditionToPlot = Pair.Type,
levelA = Unrelated ,
levelB = Consistent,
output_type ='pdf',
ant_levels= Anteriority.Levels,
med_levels= Mediality.Levels,
vary= Voltage,
group_var = Subject,
show_group_obs = FALSE ,
labels_vertical_position = 'auto',
labels_height = 'auto',
baseline= c(-500,-200),
topoplots_time_windows = list(c(-250,-150),c(-150,50),c(50,200),c(200,300),c(300,500),c(500,700),c(700,900)),
topoplots_scale = c(-2,2),
time_labels_interval = 200,
custom_labels = list(list(-450,-250,"Prime"),list(0,200,"Target")),
plotname = 'auto'
)
plot_difference_maps( data = relpriming,
conditionToPlot = Pair.Type,
levelA = Unrelated ,
levelB = Consistent,
output_type ='pdf',
topoplots_time_windows = list(c(-250,-150),c(-150,50),c(50,200),c(200,300),c(300,500),c(500,700)),
topoplots_scale = c(-2,2),
plotname = 'auto'
)
Precise in the fixed argument the start_time, end_time and time duration of your windows
plot_difference_maps( data = relpriming,
conditionToPlot = Pair.Type,
levelA = Unrelated ,
levelB = Consistent,
output_type ='pdf',
fixed= c(-300,900,100), # init_time, end_time, step
topoplots_scale = c(-2,2),
plotname = 'auto'
)
output name between quotes for the HTML file
if timeWindowMode == "custom", you need to define your custom time windows on which you will perform analyses.
generate_ERP_stats_table(
data = relpriming,
model_structure = "Voltage ~ Pair.Type + (1+ Pair.Type|Subject)",
timeWindowMode="custom",
custom_TW = list(c(-300,-150),c(-150,50),c(50,200),c(200,300),c(300,500),c(500,700)),
output_name="2020_07_02_PairTypeModels.html"
)
generate_ERP_stats_table(
data = relpriming,
model_structure = "Voltage ~ Pair.Type + (1+ Pair.Type|Subject)",
timeWindowMode="byStep",
time_step=100, min_time=-300, max_time=900,
output_name="2020_07_02_PairTypeModels.html"
)
Function to compute the correlation between an ERP effect (between two conditions) between two specific times and another variable (e.g. behavioral, demographic) that exists for each subject
erp_end_time:
behavDataset : dataset with the behavioral/demographic variable
plot_cor_with_erp_effect ( erpDataset = relpriming2,
erp_var = Pair.Type ,
erp_levelA = Unrelated ,
erp_levelB = Consistent,
erp_start_time = 700 ,
erp_end_time = 900,
behavDataset = relpriming_RT,
behav_var = Related_RTs,
subject_var = "Subject_short"
)
Among various improvements and bug fixes, here are some other planned development
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.