Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make_lights and geom_lights fail with reversed light cycle #5

Closed
matiasandina opened this issue Jun 16, 2023 · 2 comments
Closed

make_lights and geom_lights fail with reversed light cycle #5

matiasandina opened this issue Jun 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@matiasandina
Copy link
Owner

This

fed_df %>% 
  recalculate_pellets() %>% 
  ggplot(aes(Pi_Time, pellets)) + 
  geom_lights(lights_off_hour = 7, lights_on_hour = 19)+
  geom_step() +
  scale_x_datetime(breaks = dt_breaks , date_labels = "%d\n%H")

and

fed_df %>% 
  recalculate_pellets() %>% 
  ggplot(aes(Pi_Time, pellets)) + 
  geom_lights(lights_off_hour = 7, lights_on_hour = 19)+
  geom_step() +
  scale_x_datetime(breaks = dt_breaks , date_labels = "%d\n%H")

produce the same plot

image

When they should produce opposite shading patterns. I'm not sure whether the error is in the calculation itself or in the way ggplot treats geom_rect() internals.

@matiasandina matiasandina added the bug Something isn't working label Jun 16, 2023
@matiasandina
Copy link
Owner Author

Related, if there is only one day in the recording, geom_lights() is not made to go to -Inf or Inf. It ends up going from min(lights_on, lights_off) to max(lights_on, lights_off)

@matiasandina
Copy link
Owner Author

library(tidyverse)
library(fed3)
theme_set(theme(text = element_text(size = 16)))
fw_files <- list.files("/home/matias/Experiments/pilots/long_term/MLA127/FED_data/fedwatcher/2023/08/", 
                       recursive = T,
                       full.names = T)
fw_df <- map(fw_files, function(tt) read_fed(tt, lib_version = "fw")) %>%
  bind_rows()
#> Warning: One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
#> One or more parsing issues, call `problems()` on your data frame for details,
#> e.g.:
#>   dat <- vroom(...)
#>   problems(dat)

min_dt <- min(fw_df$Pi_Time)

# Normal cycle
fw_df %>% 
  filter(lubridate::day(Pi_Time) < 8) %>% 
  recalculate_pellets() %>% 
  ggplot(aes(Pi_Time, pellets)) +
  geom_lights() +
  geom_step() +
  scale_x_datetime(breaks = "6 hours", date_labels = "%H")

# Fake reversed cycle
fw_df %>% 
  filter(lubridate::day(Pi_Time) < 8) %>% 
  recalculate_pellets() %>% 
  ggplot(aes(Pi_Time, pellets)) +
  geom_lights(lights_off_hour = 7, lights_on_hour = 19) +
  geom_step() +
  scale_x_datetime(breaks = "6 hours", date_labels = "%H")

# Less than a day
fw_df %>% 
  filter(lubridate::day(Pi_Time) == 8) %>% 
  recalculate_pellets() %>% 
  ggplot(aes(Pi_Time, pellets)) +
  geom_lights(lights_off_hour = 19, lights_on_hour = 7) +
  geom_step() +
  scale_x_datetime(breaks = "6 hours", date_labels = "%H")

Created on 2023-08-11 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant