From bdd0810778786408b9aa733bc10d2fecfd22631f Mon Sep 17 00:00:00 2001 From: stemangiola Date: Thu, 3 Dec 2020 09:44:43 +1100 Subject: [PATCH 1/2] update README --- README.Rmd | 53 ++++++++++++++++++++++++++++++----------------------- README.md | 49 ++++++++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/README.Rmd b/README.Rmd index 28da045..479b071 100755 --- a/README.Rmd +++ b/README.Rmd @@ -25,6 +25,17 @@ library(tidygate) ``` +## Installation + +```{r, eval=FALSE} + +# From Github +devtools::install_github("stemangiola/tidygate") + +# From CRAN +install.package("tidygate") +``` + It interactively or programmately labels points within custom gates on two dimensions, according to tidyverse principles. The information is added to your tibble. It is based on the package `gatepoints` from Wajid Jawaid. The main benefits are @@ -34,32 +45,12 @@ The main benefits are - you can save your gates and apply the programmatically. - - **Input (tibble)** -element | dimension1 | dimension2 | annotations | ------------- | ------------- | ------------- | ------------- -`chr` or `fctr` | `chr` or `fctr` | `numeric` | ... - -**Command** `input %>% gate(element, dimension1, dimension2)` - -![](inst/tidygate.gif) - -**Output (tibble)** - -element | dimension1 | dimension2 | annotations | Gate | ------------- | ------------- | ------------- | ------------- | ------------- -`chr` or `fctr` | `chr` or `fctr` | `numeric` | ... | ... - - -## Installation - -```{r, eval=FALSE} +dimension1 | dimension2 | annotations | + ------------- | ------------- | ------------- + `chr` or `fctr` | `numeric` | ... -devtools::install_github("stemangiola/tidygate") - -``` ## Interactive gating @@ -76,6 +67,22 @@ tidygate_gate <- tidygate_gate ``` + + +![](inst/tidygate.gif) +Output tibble + +```{r echo=FALSE} + +tidygate_data %>% + mutate( gate = gate_chr( + Dim1, Dim2, + # Pre-defined gates + gate_list = tidygate::gate_list + )) + +``` + Gates are saved in a temporary file for later use ```{r, echo = FALSE} diff --git a/README.md b/README.md index 5e8111b..d9afbc0 100755 --- a/README.md +++ b/README.md @@ -18,6 +18,16 @@ heatmaps following tidy principles - [tidybulk](https://github.com/stemangiola/tidybulk) for tidy and modular transcriptomics analyses +## Installation + +``` r +# From Github +devtools::install_github("stemangiola/tidygate") + +# From CRAN +install.package("tidygate") +``` + It interactively or programmately labels points within custom gates on two dimensions, according to tidyverse principles. The information is added to your tibble. It is based on the package `gatepoints` from Wajid @@ -32,25 +42,9 @@ The main benefits are **Input (tibble)** -| element | dimension1 | dimension2 | annotations | -| --------------- | --------------- | ---------- | ----------- | -| `chr` or `fctr` | `chr` or `fctr` | `numeric` | … | - -**Command** `input %>% gate(element, dimension1, dimension2)` - -![](inst/tidygate.gif) - -**Output (tibble)** - -| element | dimension1 | dimension2 | annotations | Gate | -| --------------- | --------------- | ---------- | ----------- | ---- | -| `chr` or `fctr` | `chr` or `fctr` | `numeric` | … | … | - -## Installation - -``` r -devtools::install_github("stemangiola/tidygate") -``` +| dimension1 | dimension2 | annotations | +| --------------- | ---------- | ----------- | +| `chr` or `fctr` | `numeric` | … | ## Interactive gating @@ -67,6 +61,23 @@ tidygate_gate <- tidygate_gate ``` +![](inst/tidygate.gif) Output tibble + + ## # A tibble: 2,240 x 9 + ## group hierarchy `ct 1` `ct 2` relation cancer_ID Dim1 Dim2 gate + ## + ## 1 adrenal 1 endothel… epitheli… -1 ACC -0.874 -0.239 0 + ## 2 adrenal 1 endothel… fibrobla… -1 ACC -0.740 0.114 1 + ## 3 adrenal 1 endothel… immune_c… -1 ACC -0.988 0.118 0 + ## 4 adrenal 1 epitheli… endothel… 1 ACC 0.851 0.261 0 + ## 5 adrenal 1 epitheli… fibrobla… 1 ACC 0.839 0.320 0 + ## 6 adrenal 1 epitheli… immune_c… 1 ACC 0.746 0.337 0 + ## 7 adrenal 1 fibrobla… endothel… 1 ACC 0.722 -0.0696 0 + ## 8 adrenal 1 fibrobla… epitheli… -1 ACC -0.849 -0.317 0 + ## 9 adrenal 1 fibrobla… immune_c… 0.52 ACC -0.776 -0.383 0 + ## 10 adrenal 1 immune_c… endothel… 1 ACC 0.980 -0.116 0 + ## # … with 2,230 more rows + Gates are saved in a temporary file for later use ## [[1]] From b6a77d494b90ba8be3f1d4af9eb56a66f1f0a803 Mon Sep 17 00:00:00 2001 From: stemangiola Date: Thu, 3 Dec 2020 10:02:27 +1100 Subject: [PATCH 2/2] fix values in legend --- R/functions_chr_int.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/functions_chr_int.R b/R/functions_chr_int.R index fc33c09..38311ef 100644 --- a/R/functions_chr_int.R +++ b/R/functions_chr_int.R @@ -184,11 +184,11 @@ pretty_plot_chr_int = function(.data, # Add legend to top right, outside plot region inset_y = 0 - if (pull(.data, !!.color) %>% unique %>% is.na() %>% not()) { + if (pull(.data, !!.color) %>% unique %>% is.na() %>% not() %>% all()) { legend( "topleft", inset = c(1.05, inset_y), - legend = distinct(.data_formatted,!!.color) %>% pull(!!.color), + legend = distinct(.data,!!.color) %>% pull(!!.color), pch = 19, col = distinct(.data_formatted,!!.color, .color) %>% pull(.color), title = color_title, @@ -197,7 +197,7 @@ pretty_plot_chr_int = function(.data, ) inset_y = inset_y + distinct(.data_formatted,!!.color, .color) %>% nrow %>% magrittr::multiply_by(.1) } - if (pull(.data, !!.size) %>% unique %>% is.na() %>% not() && + if (pull(.data, !!.size) %>% unique %>% is.na() %>% not() %>% all() && (.data %>% select(!!enquo(.size)) %>% sapply(class) %in% c("numeric", "integer", "double"))) { legend( "topleft", @@ -212,11 +212,11 @@ pretty_plot_chr_int = function(.data, ) inset_y = inset_y + 0.3 } - if (pull(.data, !!.shape) %>% unique %>% is.na() %>% not()) { + if (pull(.data, !!.shape) %>% unique %>% is.na() %>% not() %>% all()) { legend( "topleft", inset = c(1.05, inset_y), - legend = distinct(.data_formatted,!!.shape) %>% pull(!!.shape), + legend = distinct(.data,!!.shape) %>% pull(!!.shape), pch = distinct(.data_formatted,!!.shape, .shape) %>% pull(.shape), col = "black", title = shape_title, @@ -292,9 +292,9 @@ gate_interactive_chr_int <- .as_matrix() # Add extra space to right of plot area; change clipping to figure - if (pull(.data, !!.color) %>% unique %>% is.na() %>% not() | - pull(.data, !!.shape) %>% unique %>% is.na() %>% not() | - (pull(.data, !!.size) %>% unique %>% is.na() %>% not() && + if (pull(.data, !!.color) %>% unique %>% is.na() %>% not() %>% all() | + pull(.data, !!.shape) %>% unique %>% is.na() %>% not() %>% all()| + (pull(.data, !!.size) %>% unique %>% is.na() %>% not() %>% all() && ( .data %>% select(!!.size) %>% sapply(class) %in% c("numeric", "integer", "double") ))) {