I am using ggcyto package in R to plot flow cytometry data, and to display stats on the plot, I am using the geom_stats() function as shown here: https://www.bioconductor.org/packages/release/bioc/vignettes/ggcyto/inst/doc/ggcyto.GatingSet.html
But while the plot and gates look fine, geom_stats is not working and I get the following warning messages when I run ggcyto()...geom_stats()
Warning messages: 1: Removed 27 rows containing missing values (geom_hex). 2: Removed 2 rows containing missing values (geom_label). 3: Removed 2 rows containing missing values (geom_label). 4: Removed 2 rows containing missing values (geom_label). 5: Removed 2 rows containing missing values (geom_label).
This is the code, but it's not a working example as the data files (FCS files exported from BD FACSdiva) are not uploaded.
# libraries ----
library(flowCore)
library(ggplot2)
library(cowplot)
library(ggcyto)
library(openCyto)
library(flowWorkspace)
# load FCS files ----
files <- list.files(path = "Folder_001/Experiment_001/", pattern = "Specimen", full.names = TRUE)
expt1 <- read.flowSet(files = files, name.keyword = "$FIL", alter.names = TRUE)
# log-transform PI and Annexin V data ----
logTrans <- logTransform(transformationId="log10-transformation", logbase=10, r=1, d=1)
trans <- transformList(c("PI.A", "BV421.A"), logTrans)
expt1.trans <- transform(expt1, trans)
# clean up NA/NaN/Inf ----
for(n in 1:length(expt1.trans)){
exprs(expt1.trans[[n]]) <- exprs(expt1.trans[[n]])[!rowSums(!is.finite(exprs(expt1.trans[[n]]))), ]
}
# Add gates (flowWorkspace) ----
gate <- rectangleGate(filterId="myRectGate", "FSC.A"=c(0, 255000), "SSC.A"=c(0, 75000))
qg <- quadGate(filterId="myQuadGate1", "PI.A"=log10(10000), "BV421.A"=log10(3000))
gated.gs <- GatingSet(expt1.trans)
addgated.gs, gate, parent = "root", name = "rect", recompute = TRUE)
addgated.gs, qg, parent = "rect", name = c("Early apoptotic", "Dead", "PI only", "Live"))
getNodesgated.gs)
recomputegated.gs)
gated.selected <- gated.gs[c(8, 6)]
# plot ----
p <- ggcyto(gated.selected, aes(x = PI.A, y = BV421.A)) +
geom_hex(bins = 200) +
geom_gate(gates) +
labs(x = "PI", y = "Annexin V") +
geom_stats()
Looking at the ggplot object created by ggcyto, it looks like the problem might be with the x and y columns in the labels data frames, which have NA's, but manually modifying these columns does not seem to have any effect.
> p.build$data[[7]]
x y label PANEL group colour fill size angle hjust vjust alpha family fontface lineheight
1 NA NA 9.16% 1 -1 black white 3.88 0 0.5 0.5 NA 1 1.2
2 NA NA 8.88% 2 -1 black white 3.88 0 0.5 0.5 NA 1 1.2
Hope that is all the relevant information, but please let me know if I missed anything. Thanks.