Skip to content

Commit

Permalink
Merge pull request #7 from tscnlab/more_imports
Browse files Browse the repository at this point in the history
  • Loading branch information
JZauner authored Dec 6, 2023
2 parents f83242c + 5461d8e commit c9e30df
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
13 changes: 11 additions & 2 deletions R/gg_day.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
#' [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).
#'
#' @param dataset A light logger dataset. Expects a `dataframe`. If not imported
#' by [LightLogR], take care to choose a sensible variable for the `x.axis.`.
#' @param x.axis,y.axis column name that contains the datetime (x, defaults to
Expand Down Expand Up @@ -82,7 +91,6 @@
#' sample.data.environment,
#' scales = "fixed",
#' end.date = "2023-08-16",
#' x.axis = Datetime,
#' y.axis.label = "mEDI (lx)",
#' aes_col = Id)
#' plot
Expand Down Expand Up @@ -210,10 +218,11 @@ gg_day <- function(dataset,
ggplot2::ggplot(ggplot2::aes(x=Time.data, y = !!y)) +
eval(geom_function_expr)(
ggplot2::aes(
x=Time.data, y = !!y,
group = {{ group }},
col = {{ aes_col }},
fill = {{ aes_fill }},
), ...) +
), ...) +
ribbon +
# Scales --------------------------------------------------------------
jco_color_scheme+
Expand Down
19 changes: 19 additions & 0 deletions R/import_LL.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ imports <- function(device,
}

import_arguments <- list(
#SpectraWear
SpectraWear = rlang::expr({
tmp <-suppressMessages(
readr::read_csv(filename,
n_max = n_max,
id = "file.name",
locale = locale,
name_repair = "universal",
...
))
tmp <- tmp %>%
dplyr::rename(MEDI = Mel
) %>%
dplyr::mutate(Datetime =
lubridate::dmy_hms(paste(Date, Time), tz = tz),
Id = paste(.data$id, .data$ls, sep = ".")
)
}),
#Speccy
Speccy = rlang::expr({
tmp <-suppressMessages(
Expand All @@ -228,6 +246,7 @@ import_arguments <- list(
id = "file.name",
locale = locale,
name_repair = "universal",
col_types = c("fccdddddddddddddddddd"),
...
))
tmp <- tmp %>%
Expand Down
Binary file modified data/supported.devices.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ bibentry(
pages = "",
url = "https://github.com/tscnlab/LightLogR",
textVersion = paste(
"Zauner, J.; Spitschan, M. (2023): LightLogR: Working With Wearable Light Logger Data. R Package, Available on https://github.com/tscnlab/LightLogR. Funded by EURAMET, co-funded by the European Union, Grant#22NRM05 MeLiDos"
"Zauner, J.; Spitschan, M. (2023): LightLogR: Working With Wearable Light Logger Data. R Package, Available on https://github.com/tscnlab/LightLogR"
)
)
10 changes: 9 additions & 1 deletion man/gg_day.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/import_Dataset.Rd

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions vignettes/articles/Day.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,18 @@ dataset.LL.partial %>%

To create a boxplot representation, we not only need to specify the geom but also what time interval we want the boxplot to span. Here the `cut_Datetime()` function from **LightLogR** comes to the rescue. It will round the datetimes to the desired interval, which then can be specified as the `group` argument of `gg_day()`. While this can be a nice representation, I don´t think it fits our goal for the overall figure in our specific case.

#### `geom_hexplot`
#### `geom_bin2d`

```{r, fig.retina=2, fig.width=7, fig.height = 4, warning=FALSE}
dataset.LL.partial %>%
gg_day(
size = 0.25, facetting = FALSE, geom = "bin2d", bins = 24) + #base plot
dataset.LL.partial %>% gg_day(
size = 0.25, facetting = FALSE, geom = "bin2d",
jco_color = FALSE, bins = 24, aes_fill = stat(count)) + #base plot
solar.reference + brown.reference + scale.correction
```

The geom family of `hex`, `bin2d`, or `density_2d` is particularly well suited if you have many, possibly overlaying observations. It reduces complexity by cutting the x- and y-axis into bins and counts how many observations fall within this bin. By choosing 24 bins, we see dominant values for every hour of the day.
The geom family of `hex`, `bin2d`, or `density_2d` is particularly well suited if you have many, possibly overlaying observations. It reduces complexity by cutting the x- and y-axis into bins and counts how many observations fall within this bin. By choosing 24 bins, we see dominant values for every hour of the day. The `jco_color = FALSE` argument is necessary to disable the default discrete color scheme of `gg_day()`, because a continuous scale is necessary for counts or densities. Finally, we habe to use the `aes_fill = stat(count)` argument to color the bins according to the number of observations in the bin[^4].

[^4]: Normally, using `ggplot2::geom_bin2d()` would automatically use the fill aesthetic for this, but `gg_day()` has certain defaults that are favorable in most cases, but is a bit more work here.

### {.unnumbered}

Expand Down

0 comments on commit c9e30df

Please sign in to comment.