Suggestion: return plotting data
A lot of preprocessing is done internally in the plotting functions.
Could be useful to have a return = c("ggplot", "data") argument to the plotting functions, giving the option to obtain the processed data (which would allow users to build their own plots, etc.)
I think the main one that does a lot of preprocessing is topoplot() and its variations (geom_topo() etc) - there is a get_scalpmap() function that gives you the interpolated scalp map. Most of the time I'd actually suggest people just convert to a data.frame. The only others I can think of that do something a bit extra are erp_image() / erp_raster() - is that what you had in mind?
Yes to all of those (:
Actually this already works quite simply for several of these functions just through how ggplot2 already works. If you assign the ggplot you can access the data directly:
library(eegUtils)
#>
#> Attaching package: 'eegUtils'
#> The following object is masked from 'package:stats':
#>
#> filter
testing <- erp_image(demo_epochs,
"A29")
head(testing$data)
#> time epoch electrode amplitude x y recording epoch_label
#> 1 -0.1972656 1 A29 4.965874 0 -92 NA NA
#> 2 -0.1894531 1 A29 -3.277943 0 -92 NA NA
#> 3 -0.1816406 1 A29 -7.161426 0 -92 NA NA
#> 4 -0.1738281 1 A29 -9.563370 0 -92 NA NA
#> 5 -0.1660156 1 A29 -15.727233 0 -92 NA NA
#> 6 -0.1582031 1 A29 -16.223555 0 -92 NA NA
#> participant_id smooth_time smooth_amp
#> 1 001 -0.1972656 NA
#> 2 001 -0.1894531 NA
#> 3 001 -0.1816406 NA
#> 4 001 -0.1738281 NA
#> 5 001 -0.1660156 -7.830837
#> 6 001 -0.1582031 -9.058729
Created on 2021-06-30 by the reprex package (v2.0.0)
There is only a single data frame is input? (That is, don't have to go layer-by-layer to see if any of them get different data?)
Right, actually, I've discovered a huge bug with erp_image() #96 that I just fixed locally, and will fix on develop shortly. For erp_image() and erp_raster(), there is only one layer, so only one data frame, so the one you get from assigning the ggplot is all you really need. topoplot() is the only one that uses multiple data frames, really. For that there is already get_scalpmap(your_data) which gives you the interpolated scalp surface. The only other data frame it needs is one with the channel locations/labels, which you can get using channels(your_data). Are there any others you can think of, or any way I can make topoplot() stuff more accessible?
I think that covers it - because the head/ears/nose are part of geom_topo right?
Yes, or can also be drawn using geom_head()
Oh right!