Skip to content

Commit

Permalink
Merge pull request #108 from shawntz/106-fix-diagnostic-plot
Browse files Browse the repository at this point in the history
fix #106: diagnostic plot margins
  • Loading branch information
shawntz authored Nov 24, 2024
2 parents b870263 + 087052d commit 459784c
Show file tree
Hide file tree
Showing 57 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions R/lpfilt.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ lpfilt_pupil <- function(x, prev_op, wp, ws, rp, rs, fs, plot_freqz) {

# plot frequency response of the filter
if (plot_freqz) {
par(mfrow = c(1, 1), oma = c(0, 0, 0, 0))
freq_response <- gsignal::freqz(filt, fs = fs)
xlim_sel <- freq_response$w <= min((ws + 10), fs_nq)
gsignal::freqz_plot(
Expand Down
30 changes: 12 additions & 18 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,14 @@ plot.eyeris <- function(x, ..., steps = NULL, num_previews = NULL,
pupil_data, num_previews,
preview_duration, hz
)
par(mfrow = c(1, num_previews))
par(mfrow = c(1, num_previews), oma = c(0, 0, 3, 0))
detrend_plotted <- FALSE
for (i in seq_along(pupil_steps)) {
for (n in 1:num_previews) {
st <- min(random_epochs[[n]]$time_orig)
et <- max(random_epochs[[n]]$time_orig)

main_panel <- ceiling(num_previews / 2)

if (n == main_panel) {
title <- paste0(pupil_steps[i], "\n[", st, " - ", et, "]")
} else {
title <- paste0("\n[", st, " - ", et, "]")
}
title <- paste0("\n[", st, " - ", et, "]")
header <- paste0(pupil_steps[i])

if (grepl("z", pupil_steps[i])) {
y_units <- "(z)"
Expand All @@ -177,7 +171,7 @@ plot.eyeris <- function(x, ..., steps = NULL, num_previews = NULL,
# used when running `plot()` by itself (and thus plotting all steps)
if (!only_liner_trend) {
if (grepl("_detrend$", pupil_steps[i]) && !detrend_plotted) {
par(mfrow = c(1, 1))
par(mfrow = c(1, 1), oma = c(0, 0, 0, 0))
robust_plot(pupil_data$time_orig, pupil_data[[pupil_steps[i - 1]]],
type = "l", col = "black", lwd = 2,
main = paste0("detrend:\n", pupil_steps[i - 1]),
Expand All @@ -190,12 +184,12 @@ plot.eyeris <- function(x, ..., steps = NULL, num_previews = NULL,
legend = c("pupil timeseries", "linear trend"),
col = c("black", "blue"), lwd = 2, lty = c(1, 2)
)
par(mfrow = c(1, num_previews))
par(mfrow = c(1, num_previews), oma = c(0, 0, 3, 0))
detrend_plotted <- TRUE
}
} else {
if (!detrend_plotted) {
par(mfrow = c(1, 1))
par(mfrow = c(1, 1), oma = c(0, 0, 0, 0))
title <- paste0(
"detrend:\n",
params$next_step[length(params$next_step) - 1]
Expand All @@ -213,7 +207,7 @@ plot.eyeris <- function(x, ..., steps = NULL, num_previews = NULL,
legend = c("pupil timeseries", "linear trend"),
col = c("black", "blue"), lwd = 2, lty = c(1, 2)
)
par(mfrow = c(1, num_previews))
par(mfrow = c(1, num_previews), oma = c(0, 0, 3, 0))
detrend_plotted <- TRUE
prompt_user()
}
Expand All @@ -232,15 +226,16 @@ plot.eyeris <- function(x, ..., steps = NULL, num_previews = NULL,
main = title, xlab = "time (ms)", ylab = y_label
)
}
graphics::mtext(header, outer = TRUE, cex = 1.25, font = 2)
}
}

par(mfrow = c(1, num_previews))
par(mfrow = c(1, num_previews), oma = c(0, 0, 3, 0))
} else {
start_index <- preview_window[1]
end_index <- min(preview_window[2], nrow(pupil_data))
sliced_pupil_data <- pupil_data[start_index:end_index, ]
par(mfrow = c(1, 1))
par(mfrow = c(1, 1), oma = c(0, 0, 0, 0))
for (i in seq_along(pupil_steps)) {
st <- min(sliced_pupil_data$time_orig)
et <- max(sliced_pupil_data$time_orig)
Expand All @@ -263,10 +258,10 @@ plot.eyeris <- function(x, ..., steps = NULL, num_previews = NULL,
)
}

par(mfrow = c(1, 1))
par(mfrow = c(1, 1), oma = c(0, 0, 0, 0))
}

par(mfrow = c(1, 1))
par(mfrow = c(1, 1), oma = c(0, 0, 0, 0))
}

draw_random_epochs <- function(x, n, d, hz) {
Expand All @@ -290,7 +285,6 @@ draw_random_epochs <- function(x, n, d, hz) {
return(drawn_epochs)
}


robust_plot <- function(x, ...) {
tryCatch(
{
Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgdown: 2.1.1
pkgdown_sha: ~
articles:
preproc-workflow: preproc-workflow.html
last_built: 2024-11-24T01:29Z
last_built: 2024-11-24T02:12Z
urls:
reference: http://shawnschwartz.com/eyeris/reference
article: http://shawnschwartz.com/eyeris/articles
Binary file modified docs/reference/Rplot002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/deblink-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/deblink-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/deblink-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/deblink-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detransient-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detransient-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detransient-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detrend-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detrend-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detrend-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detrend-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detrend-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/detrend-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-glassbox-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-glassbox-plot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-glassbox-plot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-glassbox-plot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-glassbox-plot-5.png
Binary file modified docs/reference/figures/README-glassbox-plot-6.png
Binary file modified docs/reference/glassbox-4.png
Binary file modified docs/reference/glassbox-5.png
Binary file modified docs/reference/glassbox-6.png
Binary file modified docs/reference/glassbox-7.png
Binary file modified docs/reference/glassbox-8.png
Binary file modified docs/reference/glassbox-9.png
Binary file modified docs/reference/interpolate-1.png
Binary file modified docs/reference/interpolate-2.png
Binary file modified docs/reference/interpolate-3.png
Binary file modified docs/reference/interpolate-4.png
Binary file modified docs/reference/lpfilt-2.png
Binary file modified docs/reference/lpfilt-3.png
Binary file modified docs/reference/lpfilt-4.png
Binary file modified docs/reference/lpfilt-5.png
Binary file modified docs/reference/lpfilt-6.png
Binary file modified docs/reference/zscore-2.png
Binary file modified docs/reference/zscore-3.png
Binary file modified docs/reference/zscore-4.png
Binary file modified docs/reference/zscore-5.png
Binary file modified docs/reference/zscore-6.png
Binary file modified docs/reference/zscore-7.png
Binary file modified man/figures/README-glassbox-plot-1.png
Binary file modified man/figures/README-glassbox-plot-2.png
Binary file modified man/figures/README-glassbox-plot-3.png
Binary file modified man/figures/README-glassbox-plot-4.png
Binary file modified man/figures/README-glassbox-plot-5.png
Binary file modified man/figures/README-glassbox-plot-6.png

0 comments on commit 459784c

Please sign in to comment.