Description Usage Arguments Details Author(s) Examples
View source: R/shade_components.R
Generate a dataframe and geoms to shade components of an EEG plot
1 | shade_components(components, durations)
|
components |
A character vector with the components' names. |
durations |
A character vector giving the components' durations. See details for correct format. |
The main output of the function is a dataframe that contains all the
information needed to shade the areas of your EEG components.
Simultaneously, shade_components()
will print the code you
need to add to your plot to insert your newly created component
shading. Note that you need to replace 'YOURDF'
with the name
of the object you saved the function's output to. Make sure you add
geom_rect()
before your other geoms
so the shading
lies below the data you're plotting. Don't forget to add +
before and/or after the additional lines if needed. Also note that
a specific order of geoms
in your plot may be required, as
well as certain requirements how to pass your data to
ggplot()
. See the example folder on
GitHub for
clarification.
You provide the durations as a character vector, such as e.g.
c("400 - 500", "500 - 700")
. See examples.
As you can tell from this printed output, what you get is a
combination of geom_rect()
and scale_fill_manual()
(for specifying colours). Note that scale_fill_manual()
might
interfere with other fill colouring you might have set. Depending on
what theme you use, you might need to change the default colours of
the shading. It's (two alternating) shades of grey - which is not
everyones taste. And crucially, won't work for every plot. Go ahead
and replace the colours with e.g. hex colour code or colour names
(see a list
here).
Alternatively, you could try and add
theme(panel.background = element_blank())
to get rid of the
panel background - or try a different ggplot2
theme.
Juliane Tkotz juliane.tkotz@hhu.de
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | library(tidyverse)
# Theme I want for my plot
chick_theme <- theme(legend.position = "top",
axis.title = element_text(size = 14),
axis.text = element_text(size = 12),
legend.text = element_text(size = 12),
legend.title = element_text(size = 14),
panel.background = element_blank(),
panel.grid.major = element_line(colour = "light grey"),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_line(colour = "light grey"))
# Example with the ChickWeight dataset
chicks <- ChickWeight
# Average across chicks
av_chicks <- ChickWeight %>%
group_by(Time, Diet) %>%
summarise(weight = mean(weight))
library(ForBioPsy)
shading <- shade_components(components = c("phase 1", "phase 2", "phase 3"),
durations = c("5 - 10", "10.5 - 12", "16 - 19"))
# Note the console
ggplot() +
geom_rect(data = shading,
aes(xmin = xstart, xmax = xend, ymin = -Inf, ymax = Inf,
fill = component), alpha = .5) +
scale_fill_manual('component', values = c('#E3E3E3', '#C8C6C6', '#E3E3E3')) +
geom_line(data = av_chicks, aes(x = Time, y = weight, colour = Diet)) +
chick_theme
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.