Skip to content

Latest commit

 

History

History
186 lines (134 loc) · 3.65 KB

ggcyto.GatingSet.md

File metadata and controls

186 lines (134 loc) · 3.65 KB

Visualize GatingSet with ggcyto

p <- ggcyto(gs, aes(x = CD4, y = CD8), subset = "CD3+") 
# 2d plot 
p <- p + geom_hex(bins = 64)
p

#use instrument range by overwritting limits setting in the default theme
p + theme_ggcyto(limits = "instrument")

#manually set limits
myTheme <- theme_ggcyto(limits = list(x = c(0,3.5e3), y = c(-10, 4.1e3)))
p <- p + myTheme# or xlim(0,3.5e3) + ylim(-10, 4e3) 
p

# print the default settings
theme_ggcyto_default()
## $limits
## [1] "data"
## 
## $facet
## facet_wrap(name) 
## 
## $hex_fill
## continuous_scale(aesthetics = "fill", scale_name = "gradientn", 
##     palette = gradient_n_pal(colours, values, space), na.value = na.value, 
##     trans = "sqrt", guide = guide)
## 
## $lab
## $labels
## [1] "both"
## 
## attr(,"class")
## [1] "labs_cyto"
## 
## attr(,"class")
## [1] "ggcyto_theme"
# add gate
p + geom_gate("CD4")

# add two gates
p <- p + geom_gate(c("CD4","CD8")) # short for geom_gate("CD8") + geom_gate("CD4")
p

# add stats (for all gate layers by default) and only display marker on axis
p + geom_stats() + labs_cyto("marker")

# add stats just for one specific gate
p + geom_stats("CD4")

# change stats type, background color and position
p + geom_stats("CD4", type = "count", size = 6,  color = "white", fill = "black", adjust = 0.3)

# 'subset' is abstract without specifiying it
p <- ggcyto(gs, aes(x = CD4, y = CD8)) + geom_hex() + myTheme
p
## Error in fortify_fs.GatingSet(x$data): 'subset' must be instantiated by the actual node name!
## Make sure either 'subset' is specified or the 'geom_gate' layer is added.
# it can be instantiated by gate layer
p + geom_gate(c("CD4", "CD8"))

# plot all children of the specified parent and projections
p <- ggcyto(gs, aes(x = 38, y = DR), subset = "CD4") + geom_hex(bins = 64) + geom_gate() + geom_stats()

# add gates to the arbitary(non-parent) node
ggcyto(gs, subset = "root", aes(x = CD4, y = CD8)) + geom_hex(bins = 64) + geom_gate("CD4") + myTheme

# inverse transform the axis without affecting the data
p + axis_x_inverse_trans() + axis_y_inverse_trans()

#add filter (consistent with `margin` behavior in flowViz)
# ggcyto(gs, aes(x = CD4, y = CD8), subset = "3+", filter = marginalFilter)  + geom_hex(bins = 32, na.rm = T)
class(p)
## [1] "ggcyto_GatingSet" "ggcyto_flowSet"   "ggcyto"          
## [4] "gg"               "ggplot"
# knowing that for 'ggcyto' is the semi-ggplot object since the data slot is NOT fortified to data.frame
# until it is printed/plotted.
# (other than this it is completely ggplot compatible in terms of adding layers and themes)
class(p$data)
## [1] "GatingSet"
## attr(,"package")
## [1] "flowWorkspace"
# To return a regular ggplot object
p <- as.ggplot(p)

class(p)
## [1] "gg"     "ggplot"
class(p$data)
## [1] "data.table" "data.frame"