24hr window 15 min steps

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(lmerTest)
Warning: package 'lmerTest' was built under R version 4.4.3
Loading required package: lme4
Warning: package 'lme4' was built under R version 4.4.3
Loading required package: Matrix

Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':

    lmer
The following object is masked from 'package:stats':

    step
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.4.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ readr     2.1.5
✔ ggplot2   3.5.1     ✔ stringr   1.5.1
✔ lubridate 1.9.3     ✔ tibble    3.2.1
✔ purrr     1.0.2     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ tidyr::expand() masks Matrix::expand()
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
✖ tidyr::pack()   masks Matrix::pack()
✖ tidyr::unpack() masks Matrix::unpack()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(modelr)
library(purrr)
library(emmeans)
Warning: package 'emmeans' was built under R version 4.4.3
Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
library(gridExtra)
Warning: package 'gridExtra' was built under R version 4.4.3

Attaching package: 'gridExtra'

The following object is masked from 'package:dplyr':

    combine
library(writexl)
Warning: package 'writexl' was built under R version 4.4.3
library(gt)
Warning: package 'gt' was built under R version 4.4.3
library(webshot2)
Warning: package 'webshot2' was built under R version 4.4.3
library(broom.mixed)
library(ggplot2)
library(isotree)
Warning: package 'isotree' was built under R version 4.4.3
library(tidyr)
library(ggforce)
Warning: package 'ggforce' was built under R version 4.4.3
library(plotrix)
Warning: package 'plotrix' was built under R version 4.4.3
library(lubridate)
library(KFAS)
Warning: package 'KFAS' was built under R version 4.4.3
Please cite KFAS in publications by using: 

  Jouni Helske (2017). KFAS: Exponential Family State Space Models in R. Journal of Statistical Software, 78(10), 1-39. doi:10.18637/jss.v078.i10.
library(zoo)

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric
library(ggforce)
load('Z:/Isaac/Visual Features/1-5/Sensors/3_2.RData')

Looking at 24h windows and 15 min steps

nested_sensor_15 <- nested_sensor_15 %>% 
  mutate(data=map(data,~.x %>% 
                    mutate(m_rolling_mean = rollmean(m_mean,k=96, fill=NA,align="right"),
                           m_rolling_mean_var = rollmean(m_var,k=96, fill=NA,align="right"))))
i=1

Farrow<-nested_sensor_15$data[[i]]$FD_Gestal[i]
nested_sensor_15$data[[i]]$FD_Gestal[i]
[1] "2025-04-02"
nested_sensor_15 %>% slice(i) %>% unnest(cols=c(data)) %>% 
  ggplot(aes(x=window15,y=m_rolling_mean))+
  geom_smooth(se=FALSE, span=0)+
  geom_vline(aes(xintercept = as.POSIXct(Farrow)), color = "red", linetype = "dashed")
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Warning: Removed 15609 rows containing non-finite outside the scale range
(`stat_smooth()`).

nested_sensor_15 %>% slice(i) %>% unnest(cols=c(data)) %>% 
  ggplot(aes(x=window15,y=m_rolling_mean_var))+
  geom_smooth(se=FALSE, span=0)+
  geom_vline(aes(xintercept = as.POSIXct(Farrow)), color = "red", linetype = "dashed")
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Warning: Removed 88810 rows containing non-finite outside the scale range
(`stat_smooth()`).

library(ggplot2)
library(ggforce)

# Unnest everything
plot_data <- nested_sensor_15 %>% unnest(cols = c(data))

# Plot Page 1 (Sows 1-12)
ggplot(plot_data, aes(x = window15, y = m_rolling_mean)) +
  geom_line(color = "steelblue") +
  geom_vline(aes(xintercept = as.POSIXct(FD_Gestal)), color = "red", linetype = "dashed") +
  facet_wrap_paginate(~ Sow_ID, ncol = 2, nrow = 2, page = 1) +
  theme_minimal()
Warning: Removed 118 rows containing missing values or values outside the scale range
(`geom_line()`).
Warning: Removed 2085 rows containing missing values or values outside the scale range
(`geom_vline()`).

# Create a folder to save plots so your working directory stays clean
dir.create("sow_plots")


library(tidyverse)
library(zoo)
library(lubridate)

nested_sensor_15 <- nested_sensor_15 %>%
  mutate(data = map(data, ~ {
    
    # 1. Calculate the 24-hour rolling mean (k=96)
    # We do this BEFORE filtering so the rolling window has 
    # historical data to pull from at the start of our window.
    .x <- .x %>%
      mutate(m_rolling_mean = rollmean(m_mean, k = 96, fill = NA, align = "right"))
    
    # 2. Get the farrowing date
    farrow_date <- .x$FD_Gestal[1]
    
    # 3. Filter for 2 days after farrowing
    # If window15 is POSIXct (date-time), use + days(2)
    # If window15 is Date, use + 2
    .x %>% filter(window15 <= (farrow_date + days(2)))
  }))
# The loop
for (i in 1:nrow(nested_sensor_15)) {
  
  # 1. Extract data for the current sow
  current_sow_id <- nested_sensor_15$Sow_ID[i]
  current_data <- nested_sensor_15$data[[i]]
  farrow_time <- current_data$FD_Gestal[1]
  
  # 2. Create the plot
  # Inside your for-loop:
  p <- current_data %>%
    filter(!is.na(m_rolling_mean)) %>%  # 1. Remove the 95 NAs so the line starts immediately
    ggplot(aes(x = window15, y = m_rolling_mean_var)) +
    geom_line(color = "steelblue", size = 1) +
    geom_vline(xintercept = as.POSIXct(farrow_time), color = "red", linetype = "dashed") +
    # 2. Force the Y-axis to wrap tightly around your data
    coord_cartesian(ylim = range(current_data$m_rolling_mean, na.rm = TRUE)) + 
    labs(title = paste("Sow ID:", current_sow_id),
         subtitle = "24h Rolling Mean (k=96)") +
    theme_minimal()
  
  # 3. Save the plot
  ggsave(filename = paste0("sow_plots/sow_", current_sow_id, ".png"), 
         plot = p, width = 8, height = 5)
  
  # Optional: Print progress to the console
  print(paste("Processed sow", i, "of", nrow(nested_sensor_15)))
}
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Warning: Removed 5 rows containing missing values or values outside the scale range
(`geom_line()`).
`geom_line()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
[1] "Processed sow 1 of 191"
[1] "Processed sow 2 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 3 of 191"
[1] "Processed sow 4 of 191"
Warning: Removed 263 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 5 of 191"
Warning: Removed 275 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 6 of 191"
Warning: Removed 241 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 7 of 191"
[1] "Processed sow 8 of 191"
Warning: Removed 262 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 9 of 191"
[1] "Processed sow 10 of 191"
[1] "Processed sow 11 of 191"
[1] "Processed sow 12 of 191"
[1] "Processed sow 13 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 14 of 191"
[1] "Processed sow 15 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 16 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 17 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 18 of 191"
Warning: Removed 74 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 19 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 20 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 21 of 191"
Warning: Removed 75 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 22 of 191"
Warning: Removed 177 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 23 of 191"
[1] "Processed sow 24 of 191"
[1] "Processed sow 25 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 26 of 191"
[1] "Processed sow 27 of 191"
Warning: Removed 253 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 28 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 29 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 30 of 191"
[1] "Processed sow 31 of 191"
Warning: Removed 86 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 32 of 191"
Warning: Removed 157 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 33 of 191"
Warning: Removed 70 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 34 of 191"
Warning: Removed 272 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 35 of 191"
[1] "Processed sow 36 of 191"
[1] "Processed sow 37 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 38 of 191"
Warning: Removed 46 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 39 of 191"
Warning: Removed 288 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 40 of 191"
[1] "Processed sow 41 of 191"
Warning: Removed 98 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 42 of 191"
Warning: Removed 286 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 43 of 191"
[1] "Processed sow 44 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 45 of 191"
[1] "Processed sow 46 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 47 of 191"
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 48 of 191"
[1] "Processed sow 49 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_vline()`).
[1] "Processed sow 50 of 191"
Warning: Removed 294 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 51 of 191"
Warning: Removed 61 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 52 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
[1] "Processed sow 53 of 191"
Warning: Removed 126 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 54 of 191"
[1] "Processed sow 55 of 191"
Warning: Removed 98 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 56 of 191"
Warning: Removed 97 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 57 of 191"
Warning: Removed 230 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 58 of 191"
[1] "Processed sow 59 of 191"
Warning: Removed 9 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 60 of 191"
[1] "Processed sow 61 of 191"
Warning: Removed 301 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 62 of 191"
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 63 of 191"
Warning: Removed 77 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 64 of 191"
Warning: Removed 195 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 65 of 191"
Warning: Removed 107 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 66 of 191"
Warning: Removed 96 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 67 of 191"
Warning: Removed 261 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 68 of 191"
[1] "Processed sow 69 of 191"
Warning: Removed 164 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 70 of 191"
Warning: Removed 256 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 71 of 191"
Warning: Removed 52 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 72 of 191"
Warning: Removed 131 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 73 of 191"
Warning: Removed 3 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 74 of 191"
[1] "Processed sow 75 of 191"
Warning: Removed 149 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 76 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 77 of 191"
[1] "Processed sow 78 of 191"
Warning: Removed 218 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 79 of 191"
Warning: Removed 335 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 80 of 191"
Warning: Removed 221 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 81 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in min(x): no non-missing arguments to max; returning -Inf
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_vline()`).
[1] "Processed sow 82 of 191"
Warning: Removed 65 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 83 of 191"
Warning: Removed 107 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 84 of 191"
Warning: Removed 37 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 85 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 86 of 191"
Warning: Removed 139 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 87 of 191"
[1] "Processed sow 88 of 191"
Warning: Removed 137 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 89 of 191"
[1] "Processed sow 90 of 191"
Warning: Removed 54 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 91 of 191"
Warning: Removed 79 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 92 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 93 of 191"
Warning: Removed 241 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 94 of 191"
[1] "Processed sow 95 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
[1] "Processed sow 96 of 191"
[1] "Processed sow 97 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 98 of 191"
[1] "Processed sow 99 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 100 of 191"
Warning: Removed 205 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 101 of 191"
Warning: Removed 44 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 102 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 103 of 191"
Warning: Removed 255 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 104 of 191"
[1] "Processed sow 105 of 191"
Warning: Removed 30 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 106 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 107 of 191"
[1] "Processed sow 108 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
[1] "Processed sow 109 of 191"
Warning: Removed 179 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 110 of 191"
[1] "Processed sow 111 of 191"
[1] "Processed sow 112 of 191"
[1] "Processed sow 113 of 191"
[1] "Processed sow 114 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 115 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 116 of 191"
[1] "Processed sow 117 of 191"
Warning: Removed 368 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 118 of 191"
[1] "Processed sow 119 of 191"
Warning: Removed 311 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 120 of 191"
[1] "Processed sow 121 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 122 of 191"
Warning: Removed 136 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 123 of 191"
Warning: Removed 219 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 124 of 191"
Warning: Removed 112 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 125 of 191"
[1] "Processed sow 126 of 191"
[1] "Processed sow 127 of 191"
Warning: Removed 44 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 128 of 191"
Warning: Removed 336 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 129 of 191"
Warning: Removed 241 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 130 of 191"
Warning: Removed 48 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 131 of 191"
Warning: Removed 212 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 132 of 191"
Warning: Removed 144 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 133 of 191"
[1] "Processed sow 134 of 191"
[1] "Processed sow 135 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 136 of 191"
[1] "Processed sow 137 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 138 of 191"
[1] "Processed sow 139 of 191"
[1] "Processed sow 140 of 191"
[1] "Processed sow 141 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 142 of 191"
[1] "Processed sow 143 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 144 of 191"
Warning: Removed 131 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 145 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 146 of 191"
[1] "Processed sow 147 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 148 of 191"
[1] "Processed sow 149 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_vline()`).
[1] "Processed sow 150 of 191"
Warning: Removed 96 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 151 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 152 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
[1] "Processed sow 153 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 154 of 191"
[1] "Processed sow 155 of 191"
Warning: Removed 46 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 156 of 191"
[1] "Processed sow 157 of 191"
Warning: Removed 98 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 158 of 191"
Warning: Removed 126 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 159 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 160 of 191"
[1] "Processed sow 161 of 191"
[1] "Processed sow 162 of 191"
[1] "Processed sow 163 of 191"
Warning: Removed 65 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 164 of 191"
Warning: Removed 541 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 165 of 191"
Warning: Removed 50 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 166 of 191"
[1] "Processed sow 167 of 191"
Warning: Removed 46 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 168 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 169 of 191"
[1] "Processed sow 170 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 171 of 191"
Warning: Removed 241 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 172 of 191"
Warning: Removed 74 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 173 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_vline()`).
[1] "Processed sow 174 of 191"
[1] "Processed sow 175 of 191"
Warning: Removed 296 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 176 of 191"
[1] "Processed sow 177 of 191"
[1] "Processed sow 178 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 179 of 191"
Warning: Removed 81 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 180 of 191"
Warning: Removed 309 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 181 of 191"
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
[1] "Processed sow 182 of 191"
Warning: Removed 368 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 183 of 191"
Warning: Removed 177 rows containing missing values or values outside the scale range
(`geom_line()`).
[1] "Processed sow 184 of 191"
[1] "Processed sow 185 of 191"
[1] "Processed sow 186 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 187 of 191"
[1] "Processed sow 188 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 189 of 191"
[1] "Processed sow 190 of 191"
Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
Inf
Warning in min(x, na.rm = na.rm): no non-missing arguments to max; returning
-Inf
[1] "Processed sow 191 of 191"
# Pick a sow that showed a blank plot
test_sow <- nested_sensor_15 %>% filter(Sow_ID == "28352") %>% unnest(data)

# Check if there is actually any data left after the filter
nrow(test_sow)
[1] 252
summary(test_sow$m_rolling_mean)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
 0.9760  0.9874  0.9964  1.0049  1.0216  1.0369      95