stat_pop_etho {ggetho} | R Documentation |
Compute and display a population aggregate for a variable of interest
Description
This function displays the temporal (time on the x axis) trend of variable of interest, on the y axis as a line with confidence interval as a shaded area.
Usage
stat_pop_etho(
mapping = NULL,
data = NULL,
geom = "smooth",
position = "identity",
...,
method = mean_se,
method.args = list(),
show.legend = NA,
inherit.aes = TRUE
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
method |
function used to compute the aggregate and confidence intervals.
It should return ( |
method.args |
List of additional arguments passed on to the modelling
function defined by |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Value
A ggplot layer.
References
The relevant rethomic tutorial section
See Also
-
ggetho to generate a plot object
-
stat_tile_etho to show variable of interest as colour intensity
-
stat_ld_annotations to show light and dark phases on the plot
-
ggplot2::stat_smooth to understand how to change the type of confidence interval, line colour and so forth
Other layers:
geom_peak()
,
stat_bar_tile_etho()
,
stat_ld_annotations()
Examples
library(behavr)
metadata <- data.frame(id = sprintf("toy_experiment | %02d", 1:4),
age=c(1, 5, 10, 20),
condition=c("A", "B"))
dt <- toy_activity_data(metadata, 3)
# We build a plot object
pl <- ggetho(dt, aes(y = asleep))
# A standard plot of the whole population:
pl + stat_pop_etho()
# We can also split by condition, and display the two population on different facets:
pl + stat_pop_etho() + facet_grid(condition ~ .)
## Not run:
# Instead, we can use different colour for separate conditions:
pl <- ggetho(dt, aes(y = asleep, colour = condition))
pl + stat_pop_etho()
# Sometimes, we also have numeric condition (e.g. age)
pl <- ggetho(dt, aes(y = asleep, colour = age))
pl + stat_pop_etho()
# We could want to aggregate several days of data to one circadian day (i.e. time wrapping)
# here, we also plot the invert of moving (!moving)
pl <- ggetho(dt, aes(y = !moving), time_wrap = hours(24))
pl + stat_pop_etho()
## End(Not run)