forked from stemangiola/tidygate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
executable file
·132 lines (84 loc) · 3.16 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
title: "tidygate: add gate information to your tibble"
output: github_document
---
<!---
[![Build Status](https://travis-ci.org/stemangiola/tidygate.svg?branch=master)](https://travis-ci.org/stemangiola/tidygate) [![Coverage Status](https://coveralls.io/repos/github/stemangiola/tidygate/badge.svg?branch=master)](https://coveralls.io/github/stemangiola/tidygate?branch=master)
-->
<!-- badges: start -->
[![Lifecycle:maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)
<!-- badges: end -->
Please have a look also to
- [nanny](https://github.com/stemangiola/nanny) for tidy high-level data analysis and manipulation
- [tidyHeatmap](https://github.com/stemangiola/tidyHeatmap) for producing heatmaps following tidy principles
- [tidybulk](https://github.com/stemangiola/tidybulk) for tidy and modular transcriptomics analyses
```{r, echo=FALSE, include=FALSE, }
library(knitr)
knitr::opts_chunk$set(cache = TRUE, warning = FALSE,
message = FALSE, cache.lazy = FALSE)
library(dplyr)
library(tidygate)
```
## Installation
```{r, eval=FALSE}
# From Github
devtools::install_github("stemangiola/tidygate")
# From CRAN
install.package("tidygate")
```
## What is 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
- in interactive mode you can draw your gates on extensive ggplot-like scatter plots
- you can draw multiple gates
- you can save your gates and apply the programmatically.
## Input
A tibble of this kind
dimension1 | dimension2 | annotations |
------------- | ------------- | -------------
`chr` or `fctr` | `numeric` | ...
## Step-by-step instructons for Rstudio
##### 1) Execute the following code in the console panel
```{r eval=FALSE}
tidygate_gate <-
tidygate_data %>%
mutate( gate = gate_chr( Dim1, Dim2 ) )
```
##### 2) look at the Viewer and draw a gate clicking at least three times on the plot
![](inst/tidygate.gif)
##### 3) Click the finish button on the top-right corner, or press `escape` on your keyboard
## The output tibble
```{r eval=FALSE}
tidygate_gate
```
```{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}
my_gates = tidygate::gate_list
my_gates
```
## Programmatic gating
We can use previously drawn gates to programmately add the gate column
```{r}
tidygate_data %>%
mutate( gate = gate_chr(
Dim1, Dim2,
# Pre-defined gates
gate_list = my_gates
))
```
## Subsampling
The `subsample` parameter allows you to sample a subset of your data for analysis with a fixed seed. This can be particularly useful for large datasets or for preliminary exploratory analysis. Here's how you can use it:
```{r}
# For sampling 50% of your data
result <- your_function(data, subsample = 0.5)
# For sampling 100 specific observations
result <- your_function(data, subsample = 100)
```