diff --git a/R/functions_OLD.R b/R/functions_OLD.R index 3044076..f67641a 100644 --- a/R/functions_OLD.R +++ b/R/functions_OLD.R @@ -1,3 +1,190 @@ +#' @importFrom rlang quo_is_symbol +#' @importFrom grDevices colorRampPalette +#' @importFrom RColorBrewer brewer.pal +#' @importFrom viridis viridis +#' @import dplyr +#' @import tidyr +#' @importFrom scales rescale +#' @importFrom rlang := +#' @importFrom graphics axis +#' @importFrom graphics legend +#' @importFrom graphics par +#' @importFrom utils head +#' @importFrom stringr str_pad +#' @importFrom scales alpha + +pretty_plot = function(.data, + .dim1, + .dim2, + .color=NULL, + .shape=NULL, + .size=NULL, + opacity = 1){ + + # Comply with CRAN NOTES + . = NULL + + # Get column names + .dim1 = enquo(.dim1) + .dim2 = enquo(.dim2) + .color = enquo(.color) + .shape = enquo(.shape) + + my_size_range = c(1,3) + + + + .data_formatted = + .data %>% + + # Define COLOR + when( + + # If continuous + quo_is_symbol(.color) && + (.) %>% + select(!!.color) %>% + sapply(class) %in% c("numeric", "integer", "double") ~{ + order_ = findInterval( pull(.,!!.color), sort(pull(.,!!.color))) + (.) %>% mutate(.color = grDevices::colorRampPalette( viridis(n = 5) )(n())[order_] ) + }, + + # If discrete + quo_is_symbol(.color) ~ { + how_many_colors = .data %>% distinct(!!.color) %>% nrow + (.) %>% + mutate(.color = + grDevices::colorRampPalette(RColorBrewer::brewer.pal(min(9, how_many_colors), "Set1"))(how_many_colors)[factor(!!.color)] + ) + }, + + # If not defined + ~ (.) %>% mutate(.color = "grey25") + ) %>% + + # Define SIZE + when( + + # If not defined + is.null(.size) ~ (.) %>% mutate(.size = 2 ), + + # If it is a number and not a column name + class(.size) == "numeric" ~ (.) %>% mutate(.size := !!.size ), + + # If continuous + quo_is_symbol(enquo(.size)) && + (.) %>% + select(!!enquo(.size)) %>% + sapply(class) %in% c("numeric", "integer", "double") ~ (.) %>% mutate(.size := !!enquo(.size) %>% rescale( to = my_size_range) ), + + # If discrete + quo_is_symbol(enquo(.size)) ~ { + warning("tidygate says: .size has to be a continuous variable. .size has been ignored") + (.) %>% mutate(.size = 2 ) + }, + + ~ stop("tidygate says: the parameter .size must be NULL, numeric or a symbolic column name") + ) %>% + + # Define SHAPE + when( + + # If continuous + quo_is_symbol(.shape) & + (.) %>% + select(!!.shape) %>% + sapply(class) %in% c("numeric", "integer", "double") ~ { + warning("tidygate says: .shape has to be a discrete variable. .shape has been ignored") + (.) %>% mutate(.shape = 19 ) + } , + + # If discrete + quo_is_symbol(.shape) ~ (.) %>% mutate(.shape := c(19, 17, 15, 18, 3, 4, 8, 10, 5)[factor(!!.shape)] ), + + # If not defined + ~ (.) %>% mutate(.shape = 19 ) + ) + + # Plot + .data_formatted %>% + { + plot( + (.) %>% pull(!!.dim1), + (.) %>% pull(!!.dim2), + xlim=range((.) %>% pull(!!.dim1)), + ylim=range((.) %>% pull(!!.dim2)), + bty='l', + pch=(.) %>% pull(.shape), + cex = (.) %>% pull(.size), + col=(.) %>% pull(.color) %>% alpha(opacity), + xlab = quo_names(.dim1) %>% paste(collapse= " "), + ylab = quo_names(.dim2) %>% paste(collapse= " "), + xaxt='n', + yaxt='n' + ) + } + + axis(1, tck=1, col.ticks="light gray") + axis(1, tck=-0.015, col.ticks="black", labels = FALSE) + axis(2, tck=1, col.ticks="light gray", lwd.ticks="1", las=1) + axis(2, tck=-0.015, col.ticks="black", las=1, labels = FALSE) + + # Max length of the legends titles + color_title = quo_name(.color) + shape_title = quo_name(.shape) + size_title = quo_name(.size) + max_length_titles = max(nchar(color_title), nchar(shape_title), nchar(size_title)) + color_title = stringr::str_pad(color_title, width = max_length_titles, side = "both") + shape_title = stringr::str_pad(shape_title, width = max_length_titles, side = "both") + size_title = stringr::str_pad(size_title, width = max_length_titles, side = "both") + + # Add legend to top right, outside plot region + inset_y = 0 + if( quo_is_symbol(.color)){ + legend( + "topleft", + inset=c(1.05,inset_y), + legend=distinct(.data_formatted, !!.color) %>% pull(!!.color), + pch=19, + col = distinct(.data_formatted, !!.color, .color) %>% pull(.color), + title=color_title, + box.col="white", + xjust = 0 + ) + inset_y = inset_y + distinct(.data_formatted, !!.color, .color) %>% nrow %>% magrittr::multiply_by(.1) + } + if( quo_is_symbol(enquo(.size)) && (.data %>% select(!!enquo(.size)) %>% sapply(class) %in% c("numeric", "integer", "double") )){ + legend( + "topleft", + inset=c(1.05,inset_y), + legend=distinct(.data_formatted, !!enquo(.size)) %>% pull(!!enquo(.size)) %>% range, + pch=19, + col = "black", + pt.cex = my_size_range, + title=size_title, + box.col="white", + xjust = 0 + ) + inset_y = inset_y + 0.3 + } + if( quo_is_symbol(.shape)){ + legend( + "topleft", + inset=c(1.05,inset_y), + legend=distinct(.data_formatted, !!.shape) %>% pull(!!.shape), + pch=distinct(.data_formatted, !!.shape, .shape) %>% pull(.shape), + col = "black", + title=shape_title, + box.col="white", + yjust = 0 + ) + inset_y = inset_y + distinct(.data_formatted, !!.shape, .shape) %>% nrow %>% magrittr::multiply_by(.1) + } + + + +} + #' Get points within a user drawn gate #' #' @keywords internal diff --git a/R/functions_chr_int.R b/R/functions_chr_int.R index dbcf865..fc33c09 100644 --- a/R/functions_chr_int.R +++ b/R/functions_chr_int.R @@ -24,7 +24,211 @@ parse_gate_list = function(.data, my_df){ pull(gate) } +#' @importFrom rlang quo_is_symbol +#' @importFrom grDevices colorRampPalette +#' @importFrom RColorBrewer brewer.pal +#' @importFrom viridis viridis +#' @import dplyr +#' @import tidyr +#' @importFrom scales rescale +#' @importFrom rlang := +#' @importFrom graphics axis +#' @importFrom graphics legend +#' @importFrom graphics par +#' @importFrom utils head +#' @importFrom stringr str_pad +#' @importFrom scales alpha +pretty_plot_chr_int = function(.data, + .dim1, + .dim2, + .color = NULL, + .shape = NULL, + .size = NULL, + opacity = 1) { + # Comply with CRAN NOTES + . = NULL + + # Get column names + .dim1 = enquo(.dim1) + .dim2 = enquo(.dim2) + .color = enquo(.color) + .shape = enquo(.shape) + .size = enquo(.size) + my_size_range = c(1, 3) + + + + .data_formatted = + .data %>% + + # Define COLOR + when( + + # If not defined + pull(., !!.color) %>% unique %>% is.na() ~ (.) %>% mutate(.color = "grey25"), + + # If continuous + quo_is_symbol(.color) && + (.) %>% + select(!!.color) %>% + sapply(class) %in% c("numeric", "integer", "double") ~ { + order_ = findInterval(pull(., !!.color), sort(pull(., !!.color))) + (.) %>% mutate(.color = grDevices::colorRampPalette(viridis(n = 5))(n())[order_]) + }, + + # If discrete + quo_is_symbol(.color) ~ { + how_many_colors = .data %>% distinct(!!.color) %>% nrow + (.) %>% + mutate(.color = + grDevices::colorRampPalette(RColorBrewer::brewer.pal(min( + 9, how_many_colors + ), "Set1"))(how_many_colors)[factor(!!.color)]) + } + ) %>% + + # Define SIZE + when( + # If not defined + pull(., !!.size) %>% unique %>% is.na() ~ (.) %>% mutate(.size = 2), + + # If it is a number and not a column name + class(.size) == "numeric" ~ (.) %>% mutate(.size := !!.size), + + # If continuous + quo_is_symbol(enquo(.size)) && + (.) %>% + select(!!enquo(.size)) %>% + sapply(class) %in% c("numeric", "integer", "double") ~ (.) %>% mutate(.size := !!enquo(.size) %>% rescale(to = my_size_range)), + + # If discrete + quo_is_symbol(enquo(.size)) ~ { + warning("tidygate says: .size has to be a continuous variable. .size has been ignored") + (.) %>% mutate(.size = 2) + }, + + ~ stop( + "tidygate says: the parameter .size must be NULL, numeric or a symbolic column name" + ) + ) %>% + + # Define SHAPE + when( + + # If not defined + pull(., !!.shape) %>% unique %>% is.na() ~ (.) %>% mutate(.shape = 19), + + # If continuous + quo_is_symbol(.shape) & + (.) %>% + select(!!.shape) %>% + sapply(class) %in% c("numeric", "integer", "double") ~ { + warning("tidygate says: .shape has to be a discrete variable. .shape has been ignored") + (.) %>% mutate(.shape = 19) + } , + + # If discrete + quo_is_symbol(.shape) ~ (.) %>% mutate(.shape := c(19, 17, 15, 18, 3, 4, 8, 10, 5)[factor(!!.shape)]) + + + ) + + # Plot + .data_formatted %>% + { + plot( + (.) %>% pull(!!.dim1), + (.) %>% pull(!!.dim2), + xlim = range((.) %>% pull(!!.dim1)), + ylim = range((.) %>% pull(!!.dim2)), + bty = 'l', + pch = (.) %>% pull(.shape), + cex = (.) %>% pull(.size), + col = (.) %>% pull(.color) %>% alpha(opacity), + xlab = quo_names(.dim1) %>% paste(collapse = " "), + ylab = quo_names(.dim2) %>% paste(collapse = " "), + xaxt = 'n', + yaxt = 'n' + ) + } + + axis(1, tck = 1, col.ticks = "light gray") + axis(1, + tck = -0.015, + col.ticks = "black", + labels = FALSE) + axis( + 2, + tck = 1, + col.ticks = "light gray", + lwd.ticks = "1", + las = 1 + ) + axis( + 2, + tck = -0.015, + col.ticks = "black", + las = 1, + labels = FALSE + ) + + # Max length of the legends titles + color_title = quo_name(.color) + shape_title = quo_name(.shape) + size_title = quo_name(.size) + max_length_titles = max(nchar(color_title), nchar(shape_title), nchar(size_title)) + color_title = stringr::str_pad(color_title, width = max_length_titles, side = "both") + shape_title = stringr::str_pad(shape_title, width = max_length_titles, side = "both") + size_title = stringr::str_pad(size_title, width = max_length_titles, side = "both") + + # Add legend to top right, outside plot region + inset_y = 0 + if (pull(.data, !!.color) %>% unique %>% is.na() %>% not()) { + legend( + "topleft", + inset = c(1.05, inset_y), + legend = distinct(.data_formatted,!!.color) %>% pull(!!.color), + pch = 19, + col = distinct(.data_formatted,!!.color, .color) %>% pull(.color), + title = color_title, + box.col = "white", + xjust = 0 + ) + inset_y = inset_y + distinct(.data_formatted,!!.color, .color) %>% nrow %>% magrittr::multiply_by(.1) + } + if (pull(.data, !!.size) %>% unique %>% is.na() %>% not() && + (.data %>% select(!!enquo(.size)) %>% sapply(class) %in% c("numeric", "integer", "double"))) { + legend( + "topleft", + inset = c(1.05, inset_y), + legend = distinct(.data_formatted,!!enquo(.size)) %>% pull(!!enquo(.size)) %>% range, + pch = 19, + col = "black", + pt.cex = my_size_range, + title = size_title, + box.col = "white", + xjust = 0 + ) + inset_y = inset_y + 0.3 + } + if (pull(.data, !!.shape) %>% unique %>% is.na() %>% not()) { + legend( + "topleft", + inset = c(1.05, inset_y), + legend = distinct(.data_formatted,!!.shape) %>% pull(!!.shape), + pch = distinct(.data_formatted,!!.shape, .shape) %>% pull(.shape), + col = "black", + title = shape_title, + box.col = "white", + yjust = 0 + ) + inset_y = inset_y + distinct(.data_formatted,!!.shape, .shape) %>% nrow %>% magrittr::multiply_by(.1) + } + + + +} #' Get points within a user drawn gate #' @@ -56,7 +260,7 @@ gate_interactive_chr_int <- function(.data, .dim1, .dim2, - .color = NULL, + .color = NA, .shape = NULL, .size = NULL, opacity = 1, @@ -71,6 +275,8 @@ gate_interactive_chr_int <- .dim2 = enquo(.dim2) .color = enquo(.color) .shape = enquo(.shape) + .size = enquo(.size) + name = "gate" # my df @@ -86,11 +292,11 @@ gate_interactive_chr_int <- .as_matrix() # Add extra space to right of plot area; change clipping to figure - if (quo_is_symbol(.color) | - quo_is_symbol(.shape) | - (quo_is_symbol(enquo(.size)) && + if (pull(.data, !!.color) %>% unique %>% is.na() %>% not() | + pull(.data, !!.shape) %>% unique %>% is.na() %>% not() | + (pull(.data, !!.size) %>% unique %>% is.na() %>% not() && ( - .data %>% select(!!enquo(.size)) %>% sapply(class) %in% c("numeric", "integer", "double") + .data %>% select(!!.size) %>% sapply(class) %in% c("numeric", "integer", "double") ))) { # Reset par on exit opar <- par(no.readonly = TRUE) @@ -107,14 +313,13 @@ gate_interactive_chr_int <- # Plot - my_df %>% pretty_plot( + my_df %>% pretty_plot_chr_int( !!.dim1,!!.dim2, .color = !!.color, .shape = !!.shape, # size can be number or column - .size = .size %>% when(is.null(.size) | - class(.) == "numeric" ~ (.), ~ !!enquo(.)), + .size = !!.size, opacity = opacity ) @@ -236,8 +441,10 @@ gate_programmatic_chr_int <- .dim1 = .dim1, .dim2 = .dim2 ) %>% - when(!is.null(.color) ~ mutate(., .color = .color), ~ (.)) %>% - when(!is.null(.shape) ~ mutate(., .shape = .shape), ~ (.)) %>% + when(!is.null(.color) ~ mutate(., .color = .color), ~ mutate(., .color = NA)) %>% + when(!is.null(.shape) ~ mutate(., .shape = .shape), ~ mutate(., .shape = NA)) %>% + when(!is.null(.size) ~ mutate(., .size = .size), ~ mutate(., .size = NA)) %>% + when(!is.null(.group_by) ~ mutate(., .group_by = .group_by), ~ (.)) unique_df = @@ -245,8 +452,11 @@ gate_programmatic_chr_int <- # Nesting is the case when(!is.null(.group_by) ~ nest(., data___ = .group_by), - (.)) + (.)) %>% + + distinct() + result_vector = unique_df %>% @@ -257,12 +467,11 @@ gate_programmatic_chr_int <- gate_interactive_chr_int( .dim1 = .dim1, .dim2 = .dim2, - .color = .color %>% when(is.null(.) ~ NULL, ~ !!enquo(.)), - .shape = .shape %>% when(is.null(.) ~ NULL, ~ !!enquo(.)), + .color = .color, + .shape = .shape, # size can be number of column - .size = .size %>% when(is.null(.size) | - class(.) == "numeric" ~ (.), ~ !!enquo(.)), + .size = .size, opacity = opacity, how_many_gates = how_many_gates, diff --git a/R/utilities.R b/R/utilities.R index 42ee7f1..af16d5a 100755 --- a/R/utilities.R +++ b/R/utilities.R @@ -1,3 +1,6 @@ +# Negation +not = function(is){ !is } + check_data_unique = function(.data, .element, .dim1, @@ -96,206 +99,6 @@ format_gatepoints = function(.data, .element, name, .idx) { } -#' @importFrom rlang quo_is_symbol -#' @importFrom grDevices colorRampPalette -#' @importFrom RColorBrewer brewer.pal -#' @importFrom viridis viridis -#' @import dplyr -#' @import tidyr -#' @importFrom scales rescale -#' @importFrom rlang := -#' @importFrom graphics axis -#' @importFrom graphics legend -#' @importFrom graphics par -#' @importFrom utils head -#' @importFrom stringr str_pad -#' @importFrom scales alpha -pretty_plot = function(.data, - .dim1, - .dim2, - .color = NULL, - .shape = NULL, - .size = NULL, - opacity = 1) { - # Comply with CRAN NOTES - . = NULL - - # Get column names - .dim1 = enquo(.dim1) - .dim2 = enquo(.dim2) - .color = enquo(.color) - .shape = enquo(.shape) - - my_size_range = c(1, 3) - - - - .data_formatted = - .data %>% - - # Define COLOR - when( - # If continuous - quo_is_symbol(.color) && - (.) %>% - select(!!.color) %>% - sapply(class) %in% c("numeric", "integer", "double") ~ { - order_ = findInterval(pull(., !!.color), sort(pull(., !!.color))) - (.) %>% mutate(.color = grDevices::colorRampPalette(viridis(n = 5))(n())[order_]) - }, - - # If discrete - quo_is_symbol(.color) ~ { - how_many_colors = .data %>% distinct(!!.color) %>% nrow - (.) %>% - mutate(.color = - grDevices::colorRampPalette(RColorBrewer::brewer.pal(min( - 9, how_many_colors - ), "Set1"))(how_many_colors)[factor(!!.color)]) - }, - - # If not defined - ~ (.) %>% mutate(.color = "grey25") - ) %>% - - # Define SIZE - when( - # If not defined - is.null(.size) ~ (.) %>% mutate(.size = 2), - - # If it is a number and not a column name - class(.size) == "numeric" ~ (.) %>% mutate(.size := !!.size), - - # If continuous - quo_is_symbol(enquo(.size)) && - (.) %>% - select(!!enquo(.size)) %>% - sapply(class) %in% c("numeric", "integer", "double") ~ (.) %>% mutate(.size := !!enquo(.size) %>% rescale(to = my_size_range)), - - # If discrete - quo_is_symbol(enquo(.size)) ~ { - warning("tidygate says: .size has to be a continuous variable. .size has been ignored") - (.) %>% mutate(.size = 2) - }, - - ~ stop( - "tidygate says: the parameter .size must be NULL, numeric or a symbolic column name" - ) - ) %>% - - # Define SHAPE - when( - # If continuous - quo_is_symbol(.shape) & - (.) %>% - select(!!.shape) %>% - sapply(class) %in% c("numeric", "integer", "double") ~ { - warning("tidygate says: .shape has to be a discrete variable. .shape has been ignored") - (.) %>% mutate(.shape = 19) - } , - - # If discrete - quo_is_symbol(.shape) ~ (.) %>% mutate(.shape := c(19, 17, 15, 18, 3, 4, 8, 10, 5)[factor(!!.shape)]), - - # If not defined - ~ (.) %>% mutate(.shape = 19) - ) - - # Plot - .data_formatted %>% - { - plot( - (.) %>% pull(!!.dim1), - (.) %>% pull(!!.dim2), - xlim = range((.) %>% pull(!!.dim1)), - ylim = range((.) %>% pull(!!.dim2)), - bty = 'l', - pch = (.) %>% pull(.shape), - cex = (.) %>% pull(.size), - col = (.) %>% pull(.color) %>% alpha(opacity), - xlab = quo_names(.dim1) %>% paste(collapse = " "), - ylab = quo_names(.dim2) %>% paste(collapse = " "), - xaxt = 'n', - yaxt = 'n' - ) - } - - axis(1, tck = 1, col.ticks = "light gray") - axis(1, - tck = -0.015, - col.ticks = "black", - labels = FALSE) - axis( - 2, - tck = 1, - col.ticks = "light gray", - lwd.ticks = "1", - las = 1 - ) - axis( - 2, - tck = -0.015, - col.ticks = "black", - las = 1, - labels = FALSE - ) - - # Max length of the legends titles - color_title = quo_name(.color) - shape_title = quo_name(.shape) - size_title = quo_name(.size) - max_length_titles = max(nchar(color_title), nchar(shape_title), nchar(size_title)) - color_title = stringr::str_pad(color_title, width = max_length_titles, side = "both") - shape_title = stringr::str_pad(shape_title, width = max_length_titles, side = "both") - size_title = stringr::str_pad(size_title, width = max_length_titles, side = "both") - - # Add legend to top right, outside plot region - inset_y = 0 - if (quo_is_symbol(.color)) { - legend( - "topleft", - inset = c(1.05, inset_y), - legend = distinct(.data_formatted,!!.color) %>% pull(!!.color), - pch = 19, - col = distinct(.data_formatted,!!.color, .color) %>% pull(.color), - title = color_title, - box.col = "white", - xjust = 0 - ) - inset_y = inset_y + distinct(.data_formatted,!!.color, .color) %>% nrow %>% magrittr::multiply_by(.1) - } - if (quo_is_symbol(enquo(.size)) && - (.data %>% select(!!enquo(.size)) %>% sapply(class) %in% c("numeric", "integer", "double"))) { - legend( - "topleft", - inset = c(1.05, inset_y), - legend = distinct(.data_formatted,!!enquo(.size)) %>% pull(!!enquo(.size)) %>% range, - pch = 19, - col = "black", - pt.cex = my_size_range, - title = size_title, - box.col = "white", - xjust = 0 - ) - inset_y = inset_y + 0.3 - } - if (quo_is_symbol(.shape)) { - legend( - "topleft", - inset = c(1.05, inset_y), - legend = distinct(.data_formatted,!!.shape) %>% pull(!!.shape), - pch = distinct(.data_formatted,!!.shape, .shape) %>% pull(.shape), - col = "black", - title = shape_title, - box.col = "white", - yjust = 0 - ) - inset_y = inset_y + distinct(.data_formatted,!!.shape, .shape) %>% nrow %>% magrittr::multiply_by(.1) - } - - - -} diff --git a/README.Rmd b/README.Rmd index 62ccab1..28da045 100755 --- a/README.Rmd +++ b/README.Rmd @@ -70,28 +70,18 @@ The standard way to gate points in a two-dimensional plot is to ```{r, eval = FALSE} tidygate_gate <- tidygate_data %>% - gate( - - # grouping by - c(`ct 1`, `ct 2`), - - # Dimensions - Dim1, Dim2 - ) + mutate( gate = gate_chr( Dim1, Dim2 ) ) + tidygate_gate ``` -We can save our gates in a separate variable for later use - -```{r, eval = FALSE} -my_gates = tidygate_gate %>% attr("gate") - -my_gates -``` +Gates are saved in a temporary file for later use ```{r, echo = FALSE} my_gates = tidygate::gate_list + +my_gates ``` ## Programmatic gating @@ -101,17 +91,11 @@ We can use previously drawn gates to programmately add the gate column ```{r} tidygate_data %>% - gate( - - # grouping by - c(`ct 1`, `ct 2`), - - # Dimensions + mutate( gate = gate_chr( Dim1, Dim2, - - # Pre-defined gates + # Pre-defined gates gate_list = my_gates - ) + )) ``` diff --git a/README.md b/README.md index 79d4856..5e8111b 100755 --- a/README.md +++ b/README.md @@ -61,25 +61,26 @@ on the top-right corner of the plot ``` r tidygate_gate <- tidygate_data %>% - gate( - - # grouping by - c(`ct 1`, `ct 2`), - - # Dimensions - Dim1, Dim2 - ) + mutate( gate = gate_chr( Dim1, Dim2 ) ) + tidygate_gate ``` -We can save our gates in a separate variable for later use - -``` r -my_gates = tidygate_gate %>% attr("gate") - -my_gates -``` +Gates are saved in a temporary file for later use + + ## [[1]] + ## x y + ## 1 -0.9380459 0.2784375 + ## 2 -0.9555544 -0.1695209 + ## 3 -0.3310857 0.2116150 + ## + ## [[2]] + ## x y + ## 1 0.01324749 0.2165648 + ## 2 -0.31065917 -0.1026984 + ## 3 -0.11514794 -0.2982161 + ## 4 0.48013998 0.1225183 ## Programmatic gating @@ -87,17 +88,11 @@ We can use previously drawn gates to programmately add the gate column ``` r tidygate_data %>% - gate( - - # grouping by - c(`ct 1`, `ct 2`), - - # Dimensions + mutate( gate = gate_chr( Dim1, Dim2, - - # Pre-defined gates + # Pre-defined gates gate_list = my_gates - ) + )) ``` ## # A tibble: 2,240 x 9 diff --git a/man/gate_interactive_chr_int.Rd b/man/gate_interactive_chr_int.Rd index 139ea52..dfe113a 100644 --- a/man/gate_interactive_chr_int.Rd +++ b/man/gate_interactive_chr_int.Rd @@ -8,7 +8,7 @@ gate_interactive_chr_int( .data, .dim1, .dim2, - .color = NULL, + .color = NA, .shape = NULL, .size = NULL, opacity = 1, diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index 9911221..f2b7bb8 100755 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -2,17 +2,19 @@ # # test_that("gate dimensions", { # library(dplyr) - # res = - # tidygate::tidygate_data %>% - # mutate(sh = factor(hierarchy)) %>% - # gate( - # .element = c(`ct 1`, `ct 2`), - # Dim1, Dim2, - # .color = hierarchy, - # .shape = sh, - # .size = hierarchy, - # how_many_gates = 2 - # ) +# res = +# tidygate::tidygate_data %>% +# mutate(sh = factor(hierarchy)) %>% +# mutate( +# gate = gate_chr( +# Dim1, Dim2, +# .color = hierarchy, +# .shape = sh, +# .size = hierarchy, +# how_many_gates = 2 +# ) +# ) + # # res2 = # tidygate::tidygate_data %>% diff --git a/vignettes/introdution.Rmd b/vignettes/introdution.Rmd index d2f1f4f..0f0c6ef 100755 --- a/vignettes/introdution.Rmd +++ b/vignettes/introdution.Rmd @@ -68,28 +68,18 @@ The standard way to gate points in a two-dimensional plot is to ```{r, eval = FALSE} tidygate_gate <- tidygate_data %>% - gate( - - # grouping by - c(`ct 1`, `ct 2`), - - # Dimensions - Dim1, Dim2 - ) + mutate( gate = gate_chr( Dim1, Dim2 ) ) + tidygate_gate ``` -We can save our gates in a separate variable for later use - -```{r, eval = FALSE} -my_gates = tidygate_gate %>% attr("gate") - -my_gates -``` +Gates are saved in a temporary file for later use ```{r, echo = FALSE} my_gates = tidygate::gate_list + +my_gates ``` ## Programmatic gating @@ -99,16 +89,10 @@ We can use previously drawn gates to programmately add the gate column ```{r} tidygate_data %>% - gate( - - # grouping by - c(`ct 1`, `ct 2`), - - # Dimensions + mutate( gate = gate_chr( Dim1, Dim2, - - # Pre-defined gates + # Pre-defined gates gate_list = my_gates - ) + )) ``` \ No newline at end of file