I am trying to set the x limits on a ggcyto(ggplot2) plot, but it doesn't seem to work. The x-limit that I set is squished all the way to the right and there is a lot of empty space. Not sure what else to try. I tried setting biexp scale but it looked the same.
library(ggcyto)
library(ggplot2)
library(flowCore)
fs <- read.flowSet(fcs_files, path=(dir_path))
ggcyto(fs[[2]],
aes(x = "FSC-A",
y = "SSC-A")
) +
geom_hex(bins = 26) +
xlab("") +
ylab("") +
theme(
strip.text = element_text(size = 5),
) +
scale_x_continuous(breaks = c(0, 18000), labels = function(x) formatC(x, format="e", digits =1), limits=c(0, 20000))) #+
#scale_x_flowjo_biexp(maxValue = 20000, widthBasis = -10)
Adding limits=c(0, 20000)
gives me this warning: Warning message: Removed 14 rows containing non-finite values (stat_binhex).
Don't have your data so can't reproduce the weird axis. I would check your data for negative values. Also the ggcyto
wrapper has some restrictions on your limits.
Using an example data below, I set 2 values on the first column "FSC" to be -999, and I get a similar error:
library(ggcyto)
data(GvHD)
da = GvHD[[1]]
exprs(da)[1:2,1] = -999
ggcyto(da, aes(x = `FSC-H`, y = `SSC-H`)) +
geom_hex(bins = 50) +
scale_x_continuous(breaks =c(0,800),limits = c(0,2000))
And the error:
Warning message: Removed 2 rows containing non-finite values (stat_binhex).
If I remove the entries with negative values and also use ggplot2
instead of ggcyto
, it works
da = da[rowMeans(exprs(da[,1:2])>0) == 1,]
ggplot(da,aes(x = `FSC-H`, y = `SSC-H`)) +
geom_hex(bins=50) +
scale_x_continuous(breaks =c(0,800),limits=c(0,1200))+
scale_fill_distiller(palette = "Spectral")
In your example, you can try something like:
da = fs[[2]]
da = da[rowMeans(exprs(da[,c("FSC-A","SSC-A")])>0) == 1,]
ggplot(da,aes(x = `FSC-A`,y = `SSC-A`)) +
geom_hex(bins = 26) +
scale_x_continuous(breaks = c(0, 18000),limits=c(0, 20000)))