简体   繁体   中英

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:

在此处输入图像描述

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM