How to Mimic Histogram Plot from Flowjo in R Using flowCore?

I'm new to flowCore + R. I would like to mimic a histogram plot after gating that can be manually done in FlowJo software. I got something similar but it doesn't look quite right because it is a "density" plot and is shifted. How can I get the x axis to shift over and look similar to how FlowJo outputs the plot? I tried reading this document but couldn't find a plot similar to the one in FlowJo: howtoflowcore Appreciate any guidance. Thanks.

code snippet:

library(flowCore)
parentpath <- "/parent/path"
subfolder <- "Sample 1"
fcs_files <- list.files(paste0(parentpath, subfolder), pattern = ".fcs")
fs <- read.flowSet(fcs_files)
rect.g <- rectangleGate(filterId = "main",list("FSC-A" = c(1e5, 2e5), "SSC-A" = c(3e4,1e5)))
fs_sub <- Subset(fs, rect.g)
p <- ggcyto(fs_sub[[15]], aes(x= `UV-379-A`)) +
  geom_density(fill='black', alpha = 0.4) +
  ggcyto_par_set(limits = list(x = c(-1e3, 5e4), y = c(0, 6e-5)))
p

FlowJo output:

R FlowCore output:

1 Answer

The reason that for the "shift" is that the x axis is logarithmic (base 10) in the flowJo graph. To achieve the same result in R, add

+ scale_x_log10()

after the existing code. This might interact weirdly with the axis limits you've set, so bare that in mind.

To make the y-axis "count" rather than density, you can change the first line of your ggcyto() call to:

aes(x= `UV-379-A`, y = after_stat(count)) 

Let me know if that works - I don't have your data to hand so that's all from memory!

For any purely aesthetic changes, they are relatively easy to look up.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest