Today, I want to show how this can be used to open a file containing some flow cytometry data and how to generate a plot with the data.
This is the plot, I am going to generate:
It uses the Bioconductor package flowCore. The how-to manual is here and the full reference manual is here. I'm just showing how to open and plot one file which is just a starting point for flow cytometry data. There is a longer example with more plots here.
A full flow cytometry work flow will allow opening multiple files, normalising and detailed statistics. There is lots of other packages for flow cytometry on Bioconductor.
I found this interesting: bioinformatics.ca, the home to all things bioinformatics in Canada. They ran a course in 2013 entitled Flow Cytometry Data Analysis using R (2013) and the material is available to view for free.
To use the script, you will have to download this sample file:
Put it somewhere sensible and set the working directory (setwd()) of R so that the read.FCS() function can find it.
Here is the script:
#load the package flowCore which allows the import of FCS files.
# import the data
# this read.FCS() function imports the flow data
setwd() # add the appropriate destination for your directory.
ntl<-read.FCS("NTLA01.fcs", alter.names = TRUE)
n <- as.data.frame(exprs(ntl)) # extract expression values and put into a data frame
#use ggplot2 to draw dot plot
#with colours indicating density
colfunc <- colorRampPalette(c("white", "lightblue", "green", "yellow", "red"))
# this colour palette can be changed to your taste
ggplot(n, aes(x=FSC.A, y=SSC.A)) +
ylim(0, 500000) +
stat_density2d(geom="tile", aes(fill = ..density..), contour = FALSE) +
scale_fill_gradientn(colours=colfunc(400)) + # gives the colour plot
geom_density2d(colour="black", bins=5) # draws the lines inside