Title: | Interactively Gate Points |
---|---|
Description: | Interactively gate points on a scatter plot. Interactively drawn gates are recorded and can be applied programmatically to reproduce results exactly. Programmatic gating is based on the package gatepoints by Wajid Jawaid (who is also an author of this package). |
Authors: | Stefano Mangiola [aut, cre], Wajid Jawaid [ctb], William Hutchison [aut] |
Maintainer: | Stefano Mangiola <[email protected]> |
License: | GPL-3 |
Version: | 1.0.14 |
Built: | 2024-11-15 05:53:44 UTC |
Source: | https://github.com/stemangiola/tidygate |
Demo gate data
demo_gate_data
demo_gate_data
An object of class tbl_df
(inherits from tbl
, data.frame
) with 26 rows and 3 columns.
Freehand select
fhs(data, mark = TRUE, names = TRUE, ...)
fhs(data, mark = TRUE, names = TRUE, ...)
data |
Data frame or matrix of co-ordinates. (x,y) co-ordinates for each point will be on rows. Rownames of selected points will be returned. |
mark |
Default TRUE. Predicate marking of selected points. |
names |
Default TRUE. If TRUE will return rownames of data frame with points within polygon. If FALSE will return logical vector. |
... |
Additional parameters passed to |
Freehand select function. First generate a 2D plot using R's plot function,
then select gate region by left clicking. Close polygon by right clicking.
The function will return the rownames of the enclosed points by the rownames
of th co-ordinates given in data
.
Returns character vector of rownames of the selected points from data
if
names parameter is TRUE. If names is FALSE then a logical vector indicating whether points
are in the polygon is returned.
Wajid Jawaid
if(interactive()) { x <- cbind(1:10, 1:10) rownames(x) <- 1:10 plot(x, pch = 16, col = "red") fhs(x) }
if(interactive()) { x <- cbind(1:10, 1:10) rownames(x) <- 1:10 plot(x, pch = 16, col = "red") fhs(x) }
Gate points based on their X and Y coordinates. By default, this function launches an interactive scatter plot. Colour, shape, size and alpha can be defined as constant values, or can be controlled by the values of a specified column.
If previously drawn gates are supplied to the 'programmatic_gates' argument, points will be gated programmatically. This feature allows the reproduction of previously drawn interactive gates. Programmatic gating is based on the package gatepoints by Wajid Jawaid.
gate( x, y, colour = NULL, shape = NULL, alpha = 1, size = 2, programmatic_gates = NULL )
gate( x, y, colour = NULL, shape = NULL, alpha = 1, size = 2, programmatic_gates = NULL )
x |
A vector representing the X dimension. |
y |
A vector representing the Y dimension. |
colour |
A single colour code string compatible with ggplot2. Or, a vector representing the point colour. |
shape |
A single ggplot2 shape numeric ranging from 0 to 127. Or, a vector representing the point shape, coercible to a factor of 6 or less levels. |
alpha |
A single ggplot2 alpha numeric ranging from 0 to 1. Or, a vector representing the point alpha, either a numeric or factor of 6 or less levels. |
size |
A single ggplot2 size numeric ranging from 0 to 20. Or, a vector representing the point size, either a numeric or factor of 6 or less levels. |
programmatic_gates |
A 'data.frame' of the gate brush data, as saved in 'tidygate_env$gates'. The column 'x' records X coordinates, the column 'y' records Y coordinates and the column '.gate' records the gate number. When this argument is supplied, gates will be drawn programmatically. |
A vector of strings, of the gates each X and Y coordinate pair is within. If gates are drawn interactively, they are temporarily saved to 'tidygate_env$gates'.
library(dplyr) data("demo_gate_data", package = "tidygate") # Gate points interactively if(interactive()) { mtcars |> mutate(gated = gate(x = mpg, y = wt, shape = am)) } # Gate points programmatically mtcars |> mutate(gated = gate(x = mpg, y = wt, programmatic_gates = demo_gate_data))
library(dplyr) data("demo_gate_data", package = "tidygate") # Gate points interactively if(interactive()) { mtcars |> mutate(gated = gate(x = mpg, y = wt, shape = am)) } # Gate points programmatically mtcars |> mutate(gated = gate(x = mpg, y = wt, programmatic_gates = demo_gate_data))
gate() takes as input a 'tbl' formatted as | <DIMENSION 1> | <DIMENSION 2> | <...> | and calculates the rotated dimensional space of the feature value.
gate_chr( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... ) gate_int( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... )
gate_chr( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... ) gate_int( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... )
.dim1 |
A column symbol. The x dimension |
.dim2 |
A column symbol. The y dimension |
.color |
A column symbol. Colour of points |
.shape |
A column symbol. Shape of points |
.size |
A column symbol. Size of points |
opacity |
A number between 0 and 1. The opacity level of the data points |
how_many_gates |
An integer. The number of gates to label |
.group_by |
A column symbol. The column that is used to calculate distance (i.e., normally genes) |
gate_list |
A list of gates. It is returned by gate function as attribute \"gate\". If you want to create this list yourself, each element of the list is a data frame with x and y columns. Each row is a coordinate. The order matter. |
... |
Further parameters passed to the function gatepoints::fhs |
This function allow the user to label data points in inside one or more 2D gates. This package is based on on the package gatepoints.
An character vector, with "0" for elements outside gates and "1..N" for the elements inside the N gates.
An integer vector, with 0 for elements outside gates and 1..N for the elements inside the N gates.
# Standard use - interactive if(interactive()){ tidygate::tidygate_data %>% distinct(`ct 1` , `ct 2`, Dim1, Dim2) %>% mutate(gate = gate_chr( Dim1, Dim2)) } library(magrittr) library(dplyr) # Standard use - programmatic res_distinct = tidygate::tidygate_data %>% distinct(`ct 1` , `ct 2`, Dim1, Dim2) %>% mutate(gate = gate_chr( Dim1, Dim2,gate_list = tidygate::gate_list)) # Grouping - programmatic res = tidygate::tidygate_data %>% mutate(gate = gate_chr( Dim1, Dim2, .group_by = c(`ct 1` , `ct 2`), gate_list = tidygate::gate_list ))
# Standard use - interactive if(interactive()){ tidygate::tidygate_data %>% distinct(`ct 1` , `ct 2`, Dim1, Dim2) %>% mutate(gate = gate_chr( Dim1, Dim2)) } library(magrittr) library(dplyr) # Standard use - programmatic res_distinct = tidygate::tidygate_data %>% distinct(`ct 1` , `ct 2`, Dim1, Dim2) %>% mutate(gate = gate_chr( Dim1, Dim2,gate_list = tidygate::gate_list)) # Grouping - programmatic res = tidygate::tidygate_data %>% mutate(gate = gate_chr( Dim1, Dim2, .group_by = c(`ct 1` , `ct 2`), gate_list = tidygate::gate_list ))
gate_chr
## S3 method for class 'numeric' gate_chr( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... )
## S3 method for class 'numeric' gate_chr( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... )
.dim1 |
A column symbol. The x dimension |
.dim2 |
A column symbol. The y dimension |
.color |
A column symbol. Colour of points |
.shape |
A column symbol. Shape of points |
.size |
A column symbol. Size of points |
opacity |
A number between 0 and 1. The opacity level of the data points |
how_many_gates |
An integer. The number of gates to label |
.group_by |
A column symbol. The column that is used to calculate distance (i.e., normally genes) |
gate_list |
A list of gates. It is returned by gate function as attribute \"gate\". If you want to create this list yourself, each element of the list is a data frame with x and y columns. Each row is a coordinate. The order matter. |
... |
Further parameters passed to the function gatepoints::fhs |
An character vector, with "0" for elements outside gates and "1..N" for the elements inside the N gates.
gate_int
## S3 method for class 'numeric' gate_int( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... )
## S3 method for class 'numeric' gate_int( .dim1, .dim2, .color = NULL, .shape = NULL, .size = NULL, opacity = 1, how_many_gates = 1, .group_by = NULL, gate_list = NULL, ... )
.dim1 |
A column symbol. The x dimension |
.dim2 |
A column symbol. The y dimension |
.color |
A column symbol. Colour of points |
.shape |
A column symbol. Shape of points |
.size |
A column symbol. Size of points |
opacity |
A number between 0 and 1. The opacity level of the data points |
how_many_gates |
An integer. The number of gates to label |
.group_by |
A column symbol. The column that is used to calculate distance (i.e., normally genes) |
gate_list |
A list of gates. It is returned by gate function as attribute \"gate\". If you want to create this list yourself, each element of the list is a data frame with x and y columns. Each row is a coordinate. The order matter. |
... |
Further parameters passed to the function gatepoints::fhs |
An integer vector, with 0 for elements outside gates and 1..N for the elements inside the N gates.
Create an interactive scatter plot based on user-defined X and Y coordinates. Colour, shape, size and alpha can be defined as constant values, or can be controlled by values in a specified column.
gate_interactive(x, y, colour = NULL, shape = NULL, alpha = 1, size = 2)
gate_interactive(x, y, colour = NULL, shape = NULL, alpha = 1, size = 2)
x |
A vector representing the X dimension. |
y |
A vector representing the Y dimension. |
colour |
A single colour code string compatible with ggplot2. Or, a vector representing the point colour. |
shape |
A single ggplot2 shape numeric ranging from 0 to 127. Or, a vector representing the point shape, coercible to a factor of 6 or less levels. |
alpha |
A single ggplot2 alpha numeric ranging from 0 to 1. Or, a vector representing the point alpha, either a numeric or factor of 6 or less levels. |
size |
A single ggplot2 size numeric ranging from 0 to 20. Or, a vector representing the point size, either a numeric or factor of 6 or less levels. |
A vector of strings, of the gates each X and Y coordinate pair is within. If gates are drawn interactively, they are temporarily saved to 'tidygate_env$gates'
A helpful way to repeat previous interactive lasso selections to enable reproducibility. Programmatic gating is based on the package [gatepoints](https://github.com/wjawaid/gatepoints) by Wajid Jawaid.
gate_programmatic(x, y, programmatic_gates)
gate_programmatic(x, y, programmatic_gates)
x |
A vector representing the X dimension. |
y |
A vector representing the Y dimension. |
programmatic_gates |
A 'data.frame' of the gate brush data, as saved in 'tidygate_env$gates'. The column 'x' records X coordinates, the column 'y' records Y coordinates and the column '.gate' records the gate number. |
A vector of strings, of the gates each X and Y coordinate pair is within.
Run Shiny App for interactive gating
server(input, output, session)
server(input, output, session)
input |
Server input parameter |
output |
Server output parameter |
session |
Server session parameter |
NA
Create Shiny App UI
ui
ui
An object of class shiny.tag.list
(inherits from list
) of length 4.
Fluid UI container