gg_day {LightLogR} | R Documentation |
Create a simple Time-of-Day plot of light logger data, faceted by Date
Description
gg_day()
will create a simple ggplot for every data in a dataset. The
result can further be manipulated like any ggplot. This will be sensible to
refine styling or guides.
Usage
gg_day(
dataset,
start.date = NULL,
end.date = NULL,
x.axis = Datetime,
y.axis = MEDI,
aes_col = NULL,
aes_fill = NULL,
group = Id,
geom = "point",
scales = c("fixed", "free_x", "free_y", "free"),
x.axis.breaks = hms::hms(hours = seq(0, 24, by = 3)),
y.axis.breaks = c(-10^(5:0), 0, 10^(0:5)),
y.scale = "symlog",
y.scale.sc = FALSE,
x.axis.label = "Time of Day",
y.axis.label = "Illuminance (lx, MEDI)",
format.day = "%d/%m",
title = NULL,
subtitle = NULL,
interactive = FALSE,
facetting = TRUE,
jco_color = TRUE,
...
)
Arguments
dataset |
A light logger dataset. Expects a |
start.date , end.date |
Choose an optional start or end date within your
|
x.axis , y.axis |
column name that contains the datetime (x, defaults to
|
aes_col , aes_fill |
optional arguments that define separate sets and
colors or fills them. Expects anything that works with the layer data
|
group |
Optional column name that defines separate sets. Useful for
certain geoms like |
geom |
What geom should be used for visualization? Expects a
|
scales |
For |
x.axis.breaks , y.axis.breaks |
Where should breaks occur on the x and
y.axis? Expects a |
y.scale |
How should the y-axis be scaled?
|
y.scale.sc |
|
x.axis.label , y.axis.label |
labels for the x- and y-axis. Expects a
|
format.day |
Label for each day. Default is |
title |
Plot title. Expects a |
subtitle |
Plot subtitle. Expects a |
interactive |
Should the plot be interactive? Expects a |
facetting |
Should an automated facet by day be applied? Default is
|
jco_color |
Should the |
... |
Other options that get passed to the main geom function. Can be used to adjust to adjust size, linewidth, or linetype. |
Details
Besides plotting, the function creates two new variables from the given
Datetime
:
-
Day.data
is a factor that is used for facetting withggplot2::facet_wrap()
. Make sure to use this variable, if you change the faceting manually. Also, the function checks, whether this variable already exists. If it does, it will only convert it to a factor and do the faceting on that variable. -
Time.data
is anhms
created withhms::as_hms()
that is used for the x.axis
The default scaling of the y-axis is a symlog
scale, which is a logarithmic
scale that only starts scaling after a given threshold (default = 0). This
enables values of 0 in the plot, which are common in light logger data, and
even enables negative values, which might be sensible for non-light data. See
symlog_trans()
for details on tweaking this scale. The scale can also be
changed to a normal or logarithmic scale - see the y.scale argument for more.
The default scaling of the color and fill scales is discrete, with the
ggsci::scale_color_jco()
and ggsci::scale_fill_jco()
scales. To use a
continuous scale, use the jco_color = FALSE
setting. Both fill
and
color
aesthetics are set to NULL
by default. For most geoms, this is not
important, but geoms that automatically use those aesthetics (like
geom_bin2d, where fill = stat(count)) are affected by this. Manually adding
the required aesthetic (like aes_fill = ggplot2::stat(count)
will fix
this).
Value
A ggplot object
Examples
#use `col`for separation of different sets
plot <- gg_day(
sample.data.environment,
scales = "fixed",
end.date = "2023-08-16",
y.axis.label = "mEDI (lx)",
aes_col = Id)
plot
#you can easily overwrite the color scale afterwards
plot + ggplot2::scale_color_discrete()
#or change the facetting
plot + ggplot2::facet_wrap(~Day.data + Id)