From c8a0c5c89b05d34d577cfc5e8f67ba5756db9d5c Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:37:44 +0200 Subject: [PATCH 1/9] add plate effect example --- R/data.R | 24 +++++++++++++++++++++++- data/plate_effect_example.rda | Bin 0 -> 800 bytes 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 data/plate_effect_example.rda diff --git a/R/data.R b/R/data.R index fc00cfa5..bdd96e81 100644 --- a/R/data.R +++ b/R/data.R @@ -1,4 +1,3 @@ - #' Unbalanced treatment and time sample list #' #' A sample list with 4 columns SampleName, Well, Time and Treatment @@ -86,3 +85,26 @@ #' \item{Sex}{Female (F) or Male (M) - a constraint which kind of animal may receive the respective treatment} #' } "invivo_study_treatments" + +#' Example dataset with a plate effect +#' +#' Here top and bottom row were both used as controls (in dilutions). The top +#' row however was affected differently than the bottom one. This makes +#' normalization virtually impossible. +#' +#' @docType data +#' @keywords datasets +#' @name plate_effect_example +#' @usage data(plate_effect_example) +#' @author Balazs Banfai +#' +#' @format An object of class \code{"tibble"} +#' \describe{ +#' \item{row}{Plate row} +#' \item{column}{Plate column} +#' \item{conc}{Sample concentration} +#' \item{log_conc}{Logarithm of sample concentration} +#' \item{treatment}{Sample treatment} +#' \item{readout}{Readout from experiment} +#' } +"plate_effect_example" diff --git a/data/plate_effect_example.rda b/data/plate_effect_example.rda new file mode 100644 index 0000000000000000000000000000000000000000..7ae80008999d42c18363960794a821a4eec111d9 GIT binary patch literal 800 zcmV+*1K<2YT4*^jL0KkKS;=hxtpEeN|NsB@T$P7|zwG}YomIcr-`UuQin?N$7ZuGP zn4qqxsguA0{7?k|hLoODD8d1O13(%L8fY3~000^?X`zXxCPO12&;S4cL4h>FX^DxW zCIFZMXfP8@023wv07eMJ#9$Lc5XqwuU`;TZVq$2?fF=N%37zEJ7 zGHAgRRMhlFnx2g`CelXAXaj4Jx@~;%6gurWgn)L z%eioeB!H-#ic%|qSi~W+t@NZJgW}V5ClY$h5};EB?(3vN`zWT zh)N;QyPtc8h=M=5aEjL+mV96Qc&LrIA^~Cm0D2^h4iF+H>5lB`+VmI^5fK{IrL!w~ zrnd_3FI)1tciI_fSwhMdP|@*EejYX@U@b@-UWGAzIN)4_QRJW`Bm^J_)(&X)L7^yC z8&ZB_P-diI%)tbc62TD?LlY7yT8SRGz^LpDbH)V+0AUbxF{ZH6Gi--AVQLLYk*Ym0 z(;B1A8U-KF9%%E2OT610jT9mfwK9e{52|NpM9kP4X+k@LY?ugihje|B%}$8!j?m?g zRCxWpbcE|vPnJ_MQz+Z($uTk!EX;&K6EQOp5XlKJK@8C;7K_6N%^Z+pSagS2bNIlA zaBBhj_L%KNwzB`Gu zk=Y&b;2e?M-Unn5%F2PuhLCz=yf+7^H%HVS= Date: Wed, 4 Oct 2023 10:38:52 +0200 Subject: [PATCH 2/9] ncs vignette: remove empty args --- vignettes/NCS22_talk.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index adf608d9..9e0f6c65 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -56,7 +56,7 @@ subject_data <- dat %>% select(SubjectID, Group, Sex) %>% unique() set.seed(17) # gives `bad` random assignment bc <- BatchContainer$new( - dimensions = list("batch" = 3, "location" = 11), + dimensions = list("batch" = 3, "location" = 11) ) %>% assign_random(subject_data) ``` @@ -110,7 +110,7 @@ set.seed(17) # gives `bad` random assignment ``` ```{r} bc <- BatchContainer$new( - dimensions = list("batch" = 3, "location" = 11), + dimensions = list("batch" = 3, "location" = 11) ) %>% assign_random(subject_data) ``` @@ -238,7 +238,7 @@ of interest evenly across the plate and adjust for the effect computationally. set.seed(1) #1 #2 bc <- BatchContainer$new( - dimensions = list("plate" = 3, "row" = 4, "col" = 6), + dimensions = list("plate" = 3, "row" = 4, "col" = 6) ) %>% assign_random(dat) # assign_in_order(dat) From df5c3b86cfb766f6f9003deb54e166cb4cfe8894 Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:56:15 +0200 Subject: [PATCH 3/9] ncs vignette: add plate effect example --- vignettes/NCS22_talk.Rmd | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index 9e0f6c65..95bcf58f 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -45,6 +45,60 @@ dat <- dat %>% subject_data <- dat %>% select(SubjectID, Group, Sex) %>% unique() ``` +## Batch effects matter +Here's an example of plate effect. Here both top and bottom rows of the +plate are used as controls. + +This is the experiment design: + +```{r, fig.width= 4, fig.height=3, echo = FALSE} +data("plate_effect_example") +plate_effect_example |> + ggplot() + + aes(x = column, y = row, fill = treatment, alpha = log_conc) + + geom_tile() + + theme( + panel.grid.major = element_blank(), + panel.grid.minor = element_blank() + ) + + scale_y_discrete(limits = rev) + + scale_fill_brewer(palette = "Set1") + + # make transparency more visible + scale_alpha_continuous(range = c(0.2, 1)) + + ggtitle("Design") +``` + +These are the readouts: + +```{r, fig.width= 4, fig.height=5, echo = FALSE} +p1 <- plate_effect_example |> + ggplot() + + aes(x = column, y = row, fill = readout) + + geom_tile() + + theme( + panel.grid.major = element_blank(), + panel.grid.minor = element_blank() + ) + + scale_y_discrete(limits = rev) + + viridis::scale_fill_viridis() + + ggtitle("Readout") + +p1 <- plate_effect_example |> + filter(treatment == "control") |> + mutate(column = as.numeric(column)) |> + ggplot() + + aes(x = column, y = readout, color = row) + + geom_point() + + geom_line() + + scale_color_brewer(palette = "Set1") + + ggtitle("Control") + +cowplot::plot_grid(p1, p2, nrow = 2) +``` + +Due to the plate effect, the control rows are affected differently. It is +virtually impossible to normalize readouts in a meaningful way. + ## Go fully random? * Could it be sufficient to randomly distribute samples across batches? From f6aad1a8eeff2af78ab3d7de7bebf6182e256bd9 Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:56:34 +0200 Subject: [PATCH 4/9] ncs vignette: update intro --- vignettes/NCS22_talk.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index 95bcf58f..e961a5ab 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -26,7 +26,7 @@ library(tidyverse) # Introduction -Examples in this vignette are used in a talk at NCS22. +Examples in this vignette are used were used in our presentation. It uses a subset of the `longitudinal_subject_samples` dataset. From 4e7c25ab6a125167332985e248d989c904d1a33a Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:01:06 +0200 Subject: [PATCH 5/9] ncs vignette: fmt --- vignettes/NCS22_talk.Rmd | 125 ++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 48 deletions(-) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index e961a5ab..ef385862 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -33,16 +33,18 @@ It uses a subset of the `longitudinal_subject_samples` dataset. ```{r get_data, include = TRUE} data("longitudinal_subject_samples") -dat <- longitudinal_subject_samples %>% - filter(Group %in% 1:5, Week %in% c(1,4)) %>% +dat <- longitudinal_subject_samples %>% + filter(Group %in% 1:5, Week %in% c(1, 4)) %>% select(SampleID, SubjectID, Group, Sex, Week) -# for simplicity: remove two subjects that don't have both visits -dat <- dat %>% - filter(SubjectID %in% (dat %>% count(SubjectID) %>% filter(n == 2) %>% .$SubjectID)) +# for simplicity: remove two subjects that don't have both visits +dat <- dat %>% + filter(SubjectID %in% (dat %>% count(SubjectID) %>% filter(n == 2) %>% .$SubjectID)) -subject_data <- dat %>% select(SubjectID, Group, Sex) %>% unique() +subject_data <- dat %>% + select(SubjectID, Group, Sex) %>% + unique() ``` ## Batch effects matter @@ -120,7 +122,7 @@ turns out unbalanced: ```{r, fig.width= 3, fig.height=3, echo = FALSE} bc$get_samples() %>% ggplot(aes(x = batch, fill = Group)) + - geom_bar() + + geom_bar() + labs(y = "subject count") ``` @@ -191,16 +193,23 @@ bc$get_samples() ``` ```{r, echo=FALSE} -bind_rows(head(bc$get_samples(), 3) %>% - mutate(across(everything(), as.character)), - tibble(batch = "...", - location = " ...", - SubjectID = "...", - Group = "...", Sex = "..."), - tail(bc$get_samples(), 3) %>% - mutate(across(everything(), as.character))) %>% - gt::gt() %>% gt::tab_options(table.font.size = 11, - data_row.padding = 0.1) +bind_rows( + head(bc$get_samples(), 3) %>% + mutate(across(everything(), as.character)), + tibble( + batch = "...", + location = " ...", + SubjectID = "...", + Group = "...", Sex = "..." + ), + tail(bc$get_samples(), 3) %>% + mutate(across(everything(), as.character)) +) %>% + gt::gt() %>% + gt::tab_options( + table.font.size = 11, + data_row.padding = 0.1 + ) ``` @@ -251,16 +260,23 @@ cowplot::plot_grid( ```{r, echo=FALSE} -bind_rows(head(bc$get_samples(), 3) %>% - mutate(across(everything(), as.character)), - tibble(batch = "...", - location = " ...", - SubjectID = "...", - Group = "...", Sex = "..."), - tail(bc$get_samples(), 3) %>% - mutate(across(everything(), as.character))) %>% - gt::gt() %>% gt::tab_options(table.font.size = 11, - data_row.padding = 0.1) +bind_rows( + head(bc$get_samples(), 3) %>% + mutate(across(everything(), as.character)), + tibble( + batch = "...", + location = " ...", + SubjectID = "...", + Group = "...", Sex = "..." + ), + tail(bc$get_samples(), 3) %>% + mutate(across(everything(), as.character)) +) %>% + gt::gt() %>% + gt::tab_options( + table.font.size = 11, + data_row.padding = 0.1 + ) ``` @@ -289,29 +305,37 @@ of interest evenly across the plate and adjust for the effect computationally. * sex (lower priority) ```{r} -set.seed(1) #1 #2 +set.seed(1) # 1 #2 bc <- BatchContainer$new( dimensions = list("plate" = 3, "row" = 4, "col" = 6) ) %>% assign_random(dat) -# assign_in_order(dat) +# assign_in_order(dat) ``` ```{r, fig.width= 5, fig.height=4.5, eval=FALSE} -plot_plate(bc, plate = plate, row = row, column = col, - .color = Group, title = "Initial layout by Group") -plot_plate(bc, plate = plate, row = row, column = col, - .color = Sex, title = "Initial layout by Sex") +plot_plate(bc, + plate = plate, row = row, column = col, + .color = Group, title = "Initial layout by Group" +) +plot_plate(bc, + plate = plate, row = row, column = col, + .color = Sex, title = "Initial layout by Sex" +) ``` ```{r, fig.width= 5, fig.height=4.5, echo=FALSE} cowplot::plot_grid( plotlist = list( - plot_plate(bc, plate = plate, row = row, column = col, - .color = Group, title = "Initial layout by Group"), - plot_plate(bc, plate = plate, row = row, column = col, - .color = Sex, title = "Initial layout by Sex") + plot_plate(bc1, + plate = plate, row = row, column = col, + .color = Group, title = "Initial layout by Group" + ), + plot_plate(bc1, + plate = plate, row = row, column = col, + .color = Sex, title = "Initial layout by Sex" + ) ), nrow = 2 ) @@ -332,7 +356,7 @@ bc <- optimize_multi_plate_design( within_plate_variables = c("Group"), plate = "plate", row = "row", column = "col", n_shuffle = 2, - max_iter = 500 #2000 + max_iter = 500 # 2000 ) ``` @@ -340,10 +364,14 @@ bc <- optimize_multi_plate_design( ```{r, fig.width= 5, fig.height=4.5, echo=FALSE} cowplot::plot_grid( plotlist = list( - plot_plate(bc, plate = plate, row = row, column = col, - .color = Group, title = "Initial layout by Group"), - plot_plate(bc, plate = plate, row = row, column = col, - .color = Sex, title = "Initial layout by Sex") + plot_plate(bc, + plate = plate, row = row, column = col, + .color = Group, title = "Initial layout by Group" + ), + plot_plate(bc, + plate = plate, row = row, column = col, + .color = Sex, title = "Initial layout by Sex" + ) ), nrow = 2 ) @@ -395,12 +423,13 @@ see vignette `invivo_study_design` for the full story. ```{r, fig.width=4.0, fig.hight = 5.0, echo = FALSE} layout <- crossing(row = 1:9, column = 1:12) %>% - mutate(Questions = "no") -layout$Questions[c(16, 17, 18, 19, 20, 21, - 27, 28, 33, 34, - 45, 46, - 55, 56, 66, 67, 90, 91)] <- "yes" + mutate(Questions = "no") +layout$Questions[c( + 16, 17, 18, 19, 20, 21, + 27, 28, 33, 34, + 45, 46, + 55, 56, 66, 67, 90, 91 +)] <- "yes" plot_plate(layout, .color = Questions, title = "Thank you") - ``` From fb293a9f216831814e6c0dfda47da89276256f6a Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:14:35 +0200 Subject: [PATCH 6/9] ncs vignette: add manual 2-step example --- vignettes/NCS22_talk.Rmd | 90 +++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 11 deletions(-) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index ef385862..366f0a6f 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -305,13 +305,12 @@ of interest evenly across the plate and adjust for the effect computationally. * sex (lower priority) ```{r} -set.seed(1) # 1 #2 +set.seed(1) bc <- BatchContainer$new( dimensions = list("plate" = 3, "row" = 4, "col" = 6) ) %>% - assign_random(dat) -# assign_in_order(dat) + assign_in_order(dat) ``` ```{r, fig.width= 5, fig.height=4.5, eval=FALSE} @@ -328,11 +327,11 @@ plot_plate(bc, ```{r, fig.width= 5, fig.height=4.5, echo=FALSE} cowplot::plot_grid( plotlist = list( - plot_plate(bc1, + plot_plate(bc, plate = plate, row = row, column = col, .color = Group, title = "Initial layout by Group" ), - plot_plate(bc1, + plot_plate(bc, plate = plate, row = row, column = col, .color = Sex, title = "Initial layout by Sex" ) @@ -341,13 +340,82 @@ cowplot::plot_grid( ) ``` -**2-step optimization** `multi_plate_layout()` +## 2-step optimization -* Across plate optimization using osat score as before -* Within plate optimization using distance based sample scoring function +### Across plate optimization using osat score as before +```{r, warning=FALSE} +bc1 <- optimize_design( + bc, + scoring = list( + group = osat_score_generator( + batch_vars = "plate", + feature_vars = "Group" + ), + sex = osat_score_generator( + batch_vars = "plate", + feature_vars = "Sex" + ) + ), + n_shuffle = 1, + acceptance_func = + ~ accept_leftmost_improvement(..., tolerance = 0.01), + max_iter = 150, + quiet = TRUE +) +``` + +```{r, fig.width= 5, fig.height=4.5, echo=FALSE} +cowplot::plot_grid( + plotlist = list( + plot_plate(bc1, + plate = plate, row = row, column = col, + .color = Group, title = "Layout after the first step, Group" + ), + plot_plate(bc1, + plate = plate, row = row, column = col, + .color = Sex, title = "Layout after the first step, Sex" + ) + ), + nrow = 2 +) +``` + +### Within plate optimization using distance based sample scoring function +```{r, warning=FALSE} +bc2 <- optimize_design( + bc1, + scoring = mk_plate_scoring_functions( + bc1, + plate = "plate", row = "row", column = "col", + group = "Group" + ), + shuffle_proposal_func = shuffle_with_constraints(dst = plate == .src$plate), + max_iter = 150, + quiet = TRUE +) +``` + +```{r, fig.width= 5, fig.height=4.5, echo=FALSE} +cowplot::plot_grid( + plotlist = list( + plot_plate(bc2, + plate = plate, row = row, column = col, + .color = Group, title = "Layout after the second step, Group" + ), + plot_plate(bc2, + plate = plate, row = row, column = col, + .color = Sex, title = "Layout after the second step, Sex" + ) + ), + nrow = 2 +) +``` -## Spatial arrangement +## 2-step optimization `multi_plate_layout()` + +We are performing the same optimization as before, but using the +`multi_plate_layout()` function to combine the two steps. ```{r, warning=FALSE, message=FALSE} bc <- optimize_multi_plate_design( @@ -366,11 +434,11 @@ cowplot::plot_grid( plotlist = list( plot_plate(bc, plate = plate, row = row, column = col, - .color = Group, title = "Initial layout by Group" + .color = Group, title = "After optimization, Group" ), plot_plate(bc, plate = plate, row = row, column = col, - .color = Sex, title = "Initial layout by Sex" + .color = Sex, title = "After optimization, Sex" ) ), nrow = 2 From f2989cc0f31b12a6173cc515b3fe2c51a15db7cc Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:14:47 +0200 Subject: [PATCH 7/9] _doc --- man/plate_effect_example.Rd | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 man/plate_effect_example.Rd diff --git a/man/plate_effect_example.Rd b/man/plate_effect_example.Rd new file mode 100644 index 00000000..0420eecf --- /dev/null +++ b/man/plate_effect_example.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{plate_effect_example} +\alias{plate_effect_example} +\title{Example dataset with a plate effect} +\format{ +An object of class \code{"tibble"} +\describe{ +\item{row}{Plate row} +\item{column}{Plate column} +\item{conc}{Sample concentration} +\item{log_conc}{Logarithm of sample concentration} +\item{treatment}{Sample treatment} +\item{readout}{Readout from experiment} +} +} +\usage{ +data(plate_effect_example) +} +\description{ +Here top and bottom row were both used as controls (in dilutions). The top +row however was affected differently than the bottom one. This makes +normalization virtually impossible. +} +\author{ +Balazs Banfai +} +\keyword{datasets} From 0096e15de6daf3e02c1c1a2c76084b1c9858b28b Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:47:42 +0200 Subject: [PATCH 8/9] ncs vignette: replace %>% with |> and fix p1/p2 error --- vignettes/NCS22_talk.Rmd | 56 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index 366f0a6f..5e4552fe 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -33,17 +33,18 @@ It uses a subset of the `longitudinal_subject_samples` dataset. ```{r get_data, include = TRUE} data("longitudinal_subject_samples") -dat <- longitudinal_subject_samples %>% - filter(Group %in% 1:5, Week %in% c(1, 4)) %>% +dat <- longitudinal_subject_samples |> + filter(Group %in% 1:5, Week %in% c(1, 4)) |> select(SampleID, SubjectID, Group, Sex, Week) # for simplicity: remove two subjects that don't have both visits -dat <- dat %>% - filter(SubjectID %in% (dat %>% count(SubjectID) %>% filter(n == 2) %>% .$SubjectID)) +dat <- dat |> + filter(SubjectID %in% + (dat |> count(SubjectID) |> filter(n == 2) |> pull(SubjectID))) -subject_data <- dat %>% - select(SubjectID, Group, Sex) %>% +subject_data <- dat |> + select(SubjectID, Group, Sex) |> unique() ``` @@ -85,7 +86,7 @@ p1 <- plate_effect_example |> viridis::scale_fill_viridis() + ggtitle("Readout") -p1 <- plate_effect_example |> +p2 <- plate_effect_example |> filter(treatment == "control") |> mutate(column = as.numeric(column)) |> ggplot() + @@ -113,7 +114,7 @@ set.seed(17) # gives `bad` random assignment bc <- BatchContainer$new( dimensions = list("batch" = 3, "location" = 11) -) %>% +) |> assign_random(subject_data) ``` @@ -121,7 +122,8 @@ Gone wrong: Random distribution of 31 grouped subjects into 3 batches turns out unbalanced: ```{r, fig.width= 3, fig.height=3, echo = FALSE} -bc$get_samples() %>% ggplot(aes(x = batch, fill = Group)) + +bc$get_samples() |> + ggplot(aes(x = batch, fill = Group)) + geom_bar() + labs(y = "subject count") ``` @@ -167,7 +169,7 @@ set.seed(17) # gives `bad` random assignment ```{r} bc <- BatchContainer$new( dimensions = list("batch" = 3, "location" = 11) -) %>% +) |> assign_random(subject_data) ``` @@ -177,10 +179,12 @@ bc <- BatchContainer$new( ```{r, fig.width= 5.5, fig.height=3, echo = FALSE} cowplot::plot_grid( plotlist = list( - bc$get_samples() %>% ggplot(aes(x = batch, fill = Group)) + + bc$get_samples() |> + ggplot(aes(x = batch, fill = Group)) + geom_bar() + labs(y = "subject count"), - bc$get_samples() %>% ggplot(aes(x = batch, fill = Sex)) + + bc$get_samples() |> + ggplot(aes(x = batch, fill = Sex)) + geom_bar() + labs(y = "subject count") ), @@ -194,7 +198,7 @@ bc$get_samples() ```{r, echo=FALSE} bind_rows( - head(bc$get_samples(), 3) %>% + head(bc$get_samples(), 3) |> mutate(across(everything(), as.character)), tibble( batch = "...", @@ -202,10 +206,10 @@ bind_rows( SubjectID = "...", Group = "...", Sex = "..." ), - tail(bc$get_samples(), 3) %>% + tail(bc$get_samples(), 3) |> mutate(across(everything(), as.character)) -) %>% - gt::gt() %>% +) |> + gt::gt() |> gt::tab_options( table.font.size = 11, data_row.padding = 0.1 @@ -246,10 +250,12 @@ bc <- optimize_design( ```{r, fig.width= 8, fig.height=3, echo = FALSE} cowplot::plot_grid( plotlist = list( - bc$get_samples() %>% ggplot(aes(x = batch, fill = Group)) + + bc$get_samples() |> + ggplot(aes(x = batch, fill = Group)) + geom_bar() + labs(y = "subject count"), - bc$get_samples() %>% ggplot(aes(x = batch, fill = Sex)) + + bc$get_samples() |> + ggplot(aes(x = batch, fill = Sex)) + geom_bar() + labs(y = "subject count"), bc$plot_trace(include_aggregated = TRUE) @@ -261,7 +267,7 @@ cowplot::plot_grid( ```{r, echo=FALSE} bind_rows( - head(bc$get_samples(), 3) %>% + head(bc$get_samples(), 3) |> mutate(across(everything(), as.character)), tibble( batch = "...", @@ -269,10 +275,10 @@ bind_rows( SubjectID = "...", Group = "...", Sex = "..." ), - tail(bc$get_samples(), 3) %>% + tail(bc$get_samples(), 3) |> mutate(across(everything(), as.character)) -) %>% - gt::gt() %>% +) |> + gt::gt() |> gt::tab_options( table.font.size = 11, data_row.padding = 0.1 @@ -305,11 +311,11 @@ of interest evenly across the plate and adjust for the effect computationally. * sex (lower priority) ```{r} -set.seed(1) +set.seed(4) bc <- BatchContainer$new( dimensions = list("plate" = 3, "row" = 4, "col" = 6) -) %>% +) |> assign_in_order(dat) ``` @@ -490,7 +496,7 @@ see vignette `invivo_study_design` for the full story. ```{r, fig.width=4.0, fig.hight = 5.0, echo = FALSE} -layout <- crossing(row = 1:9, column = 1:12) %>% +layout <- crossing(row = 1:9, column = 1:12) |> mutate(Questions = "no") layout$Questions[c( 16, 17, 18, 19, 20, 21, From 28d01c2a1d9ee1b968038c1e58118a03d1851924 Mon Sep 17 00:00:00 2001 From: Iakov Davydov <671660+idavydov@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:22:51 +0200 Subject: [PATCH 9/9] remove viridis call from ncs vignette --- vignettes/NCS22_talk.Rmd | 1 - 1 file changed, 1 deletion(-) diff --git a/vignettes/NCS22_talk.Rmd b/vignettes/NCS22_talk.Rmd index 5e4552fe..373df995 100644 --- a/vignettes/NCS22_talk.Rmd +++ b/vignettes/NCS22_talk.Rmd @@ -83,7 +83,6 @@ p1 <- plate_effect_example |> panel.grid.minor = element_blank() ) + scale_y_discrete(limits = rev) + - viridis::scale_fill_viridis() + ggtitle("Readout") p2 <- plate_effect_example |>