[BioC] FlowViz graphics problems

Anja Schiel a.e.schiel at medisin.uio.no
Thu Jun 4 10:44:37 CEST 2009


Hi Nishant,

xyplot( `SSC-H`~`FL1-H`| factor(name, levels = unique(name)),
> data=fs.trans[1:5])
Worked like a charm, thanks. 

And no error message any more for the polygon.

Cheers,
Anja
On Wed, 2009-06-03 at 16:22 -0700, Nishant Gopalakrishnan wrote:
> Hi Anja
> 
> data=fs.trans[1:5]))
> xyplot( `SSC-H`~`FL1-H`, data=fs.trans[1:5]) obviously works, but again
> the shingles are not in the right order.
> 
> To get the xyplots in the right order , you could try
> xyplot( `SSC-H`~`FL1-H`| factor(name, levels = unique(name),
> data=fs.trans[1:5])
> 
> So obviously the object 'name' is not present. But I thought I had
> defined it with
> read.flowSet(name.keyword = 'SAMPLE ID', phenoData = list(name = 'SAMPLE
> ID', Filename = '$FIL'))?
> 
> You can check if the names are correct using  pData(fs.trans[1:5]))
> 
> 
> And by the way, I created a polygon gate according to the example
> in ?polygonGate with
> > qrcut <- matrix(c(400,300,600,600,50,300,400,50),ncol=2,nrow=4)
> > colnames(sqrcut) <- c("FSC-H","SSC-H")
> > pg <- polygonGate(filterId="nonDebris", boundaries= sqrcut)
> and do get a gate but also this error message Warning message:
> The 'boundaries' argument is deprecated, please use '.gate' instead.
> Where would I find the information on how to correctly define the
> boundaries, does this have to do with glines?
> 
> The boundaries argument has been deprecated and will be removed in the
> next release.
> I will update the example with the .gate argument as shown below
> 
> pg <- polygonGate(filterId="nonDebris", .gate = sqrcut)
> 
> 
> Nishant
> 
> 
> Anja Schiel wrote:
> > Dear Florian, dear Deepayan,
> >
> > Thanks a lot for all the help. I have run a few more experiments and
> > looked at my data.
> > I see the problem with the huge amount of values in the lower
> > measurement margin and have decided to take your advice and use the
> > densityplot function instead of trying to make individual histograms.
> > Obviously I am rather reluctant to remove any data points from the raw
> > data due to the reasons you mention, I can not tell for sure if they
> > might not be relevant in one of the channels in advance.
> >
> > And I also realize that I would like to learn a lot more about the
> > lattice, so I might endeavour into the depth of lattice during the
> > summer!
> >
> > I have one other small issue. I have now used this to get the
> > densityplot to place the plots in the order of the files in the folder
> >   
> >> densityplot(factor(name, levels = unique(name)) ~`FL1-H`, data =
> >>     
> > fs.trans[1:5])
> > Why can't I use this then to do the same with an xyplot?
> >   
> >> xyplot(factor(name, levels = unique(name)), `SSC-H`~`FL1-H`,
> >>     
> > data=fs.trans[1:5]))
> >   
> >> xyplot( `SSC-H`~`FL1-H`, data=fs.trans[1:5]) obviously works, but again
> >>     
> > the shingles are not in the right order.
> >
> > I get this error message:
> > Error in typeof(x) : object 'name' not found
> > Error in xyplot(factor(name, levels = unique(name)), `SSC-H` ~
> > `FL1-H`,  : 
> >   error in evaluating the argument 'x' in selecting a method for
> > function 'xyplot'
> >
> > So obviously the object 'name' is not present. But I thought I had
> > defined it with
> > read.flowSet(name.keyword = 'SAMPLE ID', phenoData = list(name = 'SAMPLE
> > ID', Filename = '$FIL'))?
> >
> > I assume I am missing something in respect to the difference in what
> > densityplot does compared to xyplot.
> > I have to admit that I can't quit follow the logic behind the
> > # (factor(name, levels = unique(name))
> > to begin with, but this I should probably try to figure out myself.
> >
> > Maybe you could point me in the right direction?
> >
> > And by the way, I created a polygon gate according to the example
> > in ?polygonGate with
> >   
> >> sqrcut <- matrix(c(400,300,600,600,50,300,400,50),ncol=2,nrow=4)
> >> colnames(sqrcut) <- c("FSC-H","SSC-H")
> >> pg <- polygonGate(filterId="nonDebris", boundaries= sqrcut)
> >>     
> > and do get a gate but also this error message
> > Warning message:
> > The 'boundaries' argument is deprecated, please use '.gate' instead.
> >
> > Where would I find the information on how to correctly define the
> > boundaries, does this have to do with glines?
> >
> > Many thanks for your help,
> > Anja
> >
> > On Thu, 2009-05-21 at 11:50 -0700, Florian Hahne wrote:
> >   
> >> Anja Schiel wrote:
> >>     
> >>> Dear Deepayan, 
> >>>
> >>> Thanks a lot for your help! I very much appreciate that you take the
> >>> time to help me. Bellow some comments and another question, if you have
> >>> time.....
> >>>
> >>> On Wed, 2009-05-20 at 14:13 -0700, Deepayan Sarkar wrote:
> >>>   
> >>>       
> >>>> On Wed, May 20, 2009 at 6:06 AM, Anja Schiel <a.e.schiel at medisin.uio.no> wrote:
> >>>>     
> >>>>         
> >>>>> Hi,
> >>>>>
> >>>>> I am currently testing flowCore and flowViz and have encountered some
> >>>>> problems.
> >>>>>
> >>>>> I am running :
> >>>>> R version 2.9.0 (2009-04-17)
> >>>>> i486-pc-linux-gnu
> >>>>>
> >>>>> attached base packages:
> >>>>> [1] stats     graphics  grDevices utils     datasets  methods
> >>>>> base
> >>>>>
> >>>>> other attached packages:
> >>>>> [1] flowViz_1.8.0    lattice_0.17-25  flowCore_1.10.0  rrcov_0.5-01
> >>>>> [5] pcaPP_1.6        mvtnorm_0.9-5    robustbase_0.4-5 Biobase_2.4.1
> >>>>>
> >>>>> loaded via a namespace (and not attached):
> >>>>>  [1] feature_1.2.3      graph_1.22.2       grid_2.9.0
> >>>>> KernSmooth_2.22-22
> >>>>>  [5] ks_1.6.3           latticeExtra_0.5-4 MASS_7.2-47
> >>>>> RColorBrewer_1.0-2
> >>>>>  [9] stats4_2.9.0       tools_2.9.0
> >>>>>
> >>>>>
> >>>>> I have noticed that when I use
> >>>>> xyplot(`SSC-H` ~ `FSC-H`, data = fs.trans[[1]], filter = eGate)
> >>>>> I get a plot with the Gate defined by eGate plotted, but when I try to
> >>>>> do the same with
> >>>>> flowPlot(fs.trans[[1]], filter = eGate)
> >>>>> the gate is not drawn. Since the default settings seem to be filter =
> >>>>> NULL (and I pass eGate to filter) and showFilter = TRUE I am wondering
> >>>>> if this is a glinch in the system or if my command is wrong.
> >>>>>       
> >>>>>           
> >>>> The 'flowPlot' function is not really maintained any more; the method
> >>>> for "flowFrame" does have a 'filter' argument, but it is never used in
> >>>> the actual function definition. xyplot() should be able to do
> >>>> everything flowPlot does. If not, please let us know.
> >>>>
> >>>>     
> >>>>         
> >>>>> Second I am somewhat confused about the plot function. When I transform
> >>>>> my FL-H signals with
> >>>>> fs.trans <- transform('FL1-H' = asinh, 'FL2-H' = asinh) %on% fs
> >>>>> and then run
> >>>>> plot (fs.trans[[7]], 'FL1-H', breaks=256)
> >>>>> I get a histogram with all my data crammed into the left corner due to
> >>>>> the y-axis scale that seems to be extremely large.
> >>>>>       
> >>>>>           
> >>>> The following seems to work for me:
> >>>>
> >>>> data(GvHD)
> >>>> fs <- GvHD
> >>>> fs.trans <- transform('FL1-H' = asinh, 'FL2-H' = asinh) %on% fs
> >>>> plot(fs[[7]], "FL1-H") ## most of the data in left-most bin
> >>>> plot(fs.trans[[7]], "FL1-H") ## much more spread out
> >>>>
> >>>> So we need a reproducible example to figure out why you are seeing
> >>>> different behavior.
> >>>>
> >>>>     
> >>>>         
> >>> It seems that my original FACS data must be different than the one used
> >>> for GvHD. I do see a relatively normal histogram with the GvHD data set,
> >>> as you point out. But when I use my own files the y-axis is set to 30
> >>> 000 and not like in the example to 3000. 
> >>>
> >>> By the way, the problem becomes more obvious if I actually set the
> >>> breaks. If i set the breaks=256 then my graph gets extremely 'small', if
> >>> I do the same with the GvHD the effect is not the same.
> >>>
> >>> I have attached 3 png files to show you what I get.
> >>>
> >>> I could sent you some of my original files (like one with no signal in
> >>> FL1-H and one with a signal), but I am not sure if I can just attach
> >>> those to an e-mail. Maybe I can sent you an zip archive?
> >>>   
> >>>       
> >> Hi Anja,
> >> maybe I can chip in here:
> >> It seems that your data has tons of values on the lower measurement 
> >> margin, quite a common problem for flow data. The more sophisticated 
> >> plotting functions in flowViz (e.g. densityplot) try to ignore these 
> >> artefactual values, the simple histogram in the plot function does not. 
> >> You have a couple of options here:
> >> 1.) remove those values before plotting. There is the boundaryFilter 
> >> function which should help you do that. Please note that margin events 
> >> might not be particularly informative in one channel, but they might 
> >> have perfectly fine values in others, so blindly removing them for other 
> >> purposes than visualization is usually not a good idea.
> >> 2.) Play around with ylim once this is fixed. This however will only 
> >> clip the extremely large bin at around 0 and the picture might not be 
> >> particularly nice.
> >> 3.) If you have multiple FCS files in a flowSet you could use the 
> >> densityplot function. As mentioned before, this should ignore the margin 
> >> events, although they are still indicated in the plot by little bars, as 
> >> far as I remember. I guess there should be a densityplot method for 
> >> flowFrames as well, and I will talk to Deepayan to add this for the next 
> >> release.
> >>     
> >>>   
> >>>       
> >>>>> Also the axis changes
> >>>>> between the files. I have tried to figure out how this function works
> >>>>> (checked the normal and lattice information), but I am clearly not
> >>>>> understanding what is the underlying set of data points that determines
> >>>>> the y-axis scale. I would like to know how to reduce the y-axis scale
> >>>>> and keep it constant between different files (at least if this is not
> >>>>> something totally stupid to try).
> >>>>>       
> >>>>>           
> >>>> I'm not sure what you mean. Different calls with different flow frames
> >>>> will have different scales, based on the data for that frame. You
> >>>> should be able to explicitly specify 'xlim' and 'ylim' to be the same
> >>>> in all calls. This doesn't work now, and that's a bug.  We will fix it
> >>>> soon.
> >>>>
> >>>>     
> >>>>         
> >>> Well that is related to the problem above. I tried to pass xlim and ylim
> >>> to the plot but nothing happened. I didn't get an error message either
> >>> so I thought I was doing it wrong (but if I define xlim and ylim in
> >>> xyplot it does work). So I was a bit confused. But if it is a bug then
> >>> in theory what I tried was correct and once it is fixed it should work.
> >>> In principal my idea was that I could just force the scale to be smaller
> >>> on the plot to make my data look better. It might also be necessaryr if I
> >>> need files for presentations or publications as it is usually expected
> >>> that all axis are of the same scale.
> >>>       
> >> That is a reason why I prefer density plots. They are already scaled in 
> >> a way, and having similar axes is much easier. Hard to do that on a 
> >> frequency histogram when your sample sizes differ a lot...
> >>     
> >>>  
> >>>
> >>>   
> >>>       
> >>>> You could always use densityplot() instead to compare multiple FCS files.
> >>>>
> >>>> densityplot(~`FL1-H` | names, data = fs.trans[1:5])
> >>>>
> >>>>     
> >>>>         
> >>> And in fact this is probably a better way to combine several 'signals'
> >>> in one plot to be honest.
> >>>
> >>>   
> >>>       
> >>>>> Third, I have created densityplots and noticed that the order of files
> >>>>> is not like the order in the phenoData info. In phenoData the files are
> >>>>> ordered according to their file-names (or more precise by the trailing
> >>>>> numbers given by CellQuest), while they are plotted in some kind of
> >>>>> alphabetical order in densityplot. Is it possible to pass an argument to
> >>>>> densityplot that will plot the files in the file-names order?
> >>>>>       
> >>>>>           
> >>>> Yes, that's the default for factor levels (see ?factor) when the file
> >>>> names get converted to a factor. You can control the order by
> >>>> specifying the levels explicitly. For example, compare:
> >>>>
> >>>> densityplot(factor(name, levels = rev(unique(name))) ~`FL1-H`, data =
> >>>> fs.trans[1:5])
> >>>>
> >>>> and
> >>>>
> >>>> densityplot(factor(name, levels = unique(name)) ~`FL1-H`, data = fs.trans[1:5])
> >>>>
> >>>>     
> >>>>         
> >>> Exactly what I needed! Perfect.
> >>>
> >>>   
> >>>       
> >>>>> And is it also possible to have the plot in black and white and not in color?
> >>>>>       
> >>>>>           
> >>>> Yes, e.g.
> >>>>
> >>>> densityplot( ~`FL1-H`, data = fs.trans[1:5], par.settings =
> >>>> standard.theme(color = FALSE))
> >>>>
> >>>> See ?trellis.device and ?flowViz.par.get for more details.
> >>>>
> >>>>     
> >>>>         
> >>> I admit that the higher plot functions are still a bit of a miracle to
> >>> me but I think I start getting how to change some higher level
> >>> functions. 
> >>>   
> >>>       
> >> If you are not afraid of a lattice overdose, I strongly recommend 
> >> Deepayan's Springer book...
> >>     
> >>>   
> >>>       
> >>>>> I have also tried different gates and managed to create ellipsoid,
> >>>>> rectangular and n2Filter, but failed to produce a polygon gate. Could
> >>>>> anyone provide me with an simple example how to do that?
> >>>>>       
> >>>>>           
> >>>> See the example in ?polygonGate.
> >>>>
> >>>>     
> >>>>         
> >>> Ok, I missed this example, my fault. I have now managed to get an
> >>> polygon gate!
> >>>
> >>>   
> >>>       
> >>>>> And a last question, how could I produce a densityplot where I have an
> >>>>> overaly instead of shingles for several files in one figure (such as is
> >>>>> often used for publications, to show the shift from unstained, isotype
> >>>>> control to specific staining).
> >>>>>       
> >>>>>           
> >>>> Unfortunately that's not yet supported by  the "flowSet" densityplot
> >>>> method. You could however use the underlying lattice functions
> >>>> directly to get what you want:
> >>>>
> >>>> tmpe <-
> >>>>     fsApply(fs.trans[1:6],
> >>>>             function(x) exprs(x)[, "FL1-H"],
> >>>>             simplify = FALSE)
> >>>>
> >>>> densityplot(~data, do.call(make.groups, tmpe), groups = which,
> >>>>             plot.points = FALSE, auto.key = list(columns = 3))
> >>>>
> >>>>     
> >>>>         
> >>> This works nicely too. Thanks.
> >>>
> >>>   
> >>>       
> >>>> -Deepayan
> >>>>     
> >>>>         
> >>> I have another question now. I was wondering if I can use four
> >>> rectangular gates at the same time. This would be a bit like having
> >>> quadrant statistics in other FACS software. I tried this by creating
> >>> four gates with
> >>> UL <- rectangleGate(filterId='UL', 'SSC-H' = c(400, 1000), 'FSC-H' =
> >>> c(0,500))
> >>> LL <- rectangleGate(filterId='LL', 'SSC-H' = c(0, 400), 'FSC-H' =
> >>> c(0,500))
> >>> UR <- rectangleGate(filterId='UR', 'SSC-H' = c(400, 1000), 'FSC-H' =
> >>> c(500,1000))
> >>> LR <- rectangleGate(filterId='LR', 'SSC-H' = c(0, 400), 'FSC-H' =
> >>> c(500,1000))
> >>> Now I can create subsets for each of these gates and get the percentages
> >>> gated and create results with
> >>> result_LL <- filter(fs.trans[1:4], LL)
> >>> Percent.LL <- lapply(result_LL, summary)
> >>> Percent.LL
> >>> I have used FSC and SSC for this example but obviously this is something
> >>> I eventually want to do with two fluorescent channels to identify double
> >>> positive populations.
> >>>
> >>> I was wondering if I can now create a graph in which all 4 gates are
> >>> plotted and the percentage in each gate is also plotted?
> >>>   
> >>>       
> >> In this case you could directly use the quadGate class (see ? quadGate). 
> >> flowViz knows how to plot those.
> >> data(GvHD)
> >> foo <- GvHD[[1]]
> >> qg <- quadGate("FSC-H"=500, "SSC-H"=400)
> >> xyplot(`FSC-H` ~ `SSC-H`, foo, filter=qg)
> >>
> >> Adding additional gates to a plot is also possible using the glpolygon 
> >> or glpoints methods for trellis-type plots and the gpoints or glines 
> >> methods for base graphics plots. For the trellis plots you could either 
> >> adjust the panel function to deal with multiple gates and call glpolygon 
> >> in there, or you could use trellis.focus() to get to a particular panel 
> >> in your plot (by clicking on it, or you get it for free if there is only 
> >> one...) and now you can interactively add whatever you like. 
> >> trellis.unfocus() will get rid of the red boundary after you are done.
> >>
> >> xyplot(`FSC-H` ~ `SSC-H`, foo)
> >> trellis.focus()
> >> glpolygon(UL, gpar=list(gate=list(col="black", fill="red", alpha=0.2)))
> >> glpolygon(LL, gpar=list(gate=list(col="black", fill="blue", alpha=0.2)))
> >> glpolygon(UR, gpar=list(gate=list(col="black", fill="green", alpha=0.2)))
> >> glpolygon(LR, gpar=list(gate=list(col="black", fill="black", alpha=0.2)))
> >> trellis.unfocus()
> >>
> >> Florian
> >>
> >>     
> >>> I have failed in plotting all 4 gates and I looked at the filterSet
> >>> function but I am not sure if making a filter set is the right way to do
> >>> this? And in fact I am not sure that this is possible at all. But from
> >>> what I have figured out about lattice I thought that it is possible to
> >>> 'add' further information to a graph after it is created. Maybe you can
> >>> point me in the right direction how to do this?
> >>>
> >>> And I would like to thank you for the time and effort you have put into
> >>> making this package for Flow-data. I have been searching for
> >>> Flow-software working in Linux some time now and really this is the
> >>> first time I have come across something that allows me to get some nice
> >>> output and at the same time control over what I am doing with my data. I
> >>> have used R mainly for microarray data in the past, so my learning curve
> >>> wasn't that steep this time, so this might not be true for first time
> >>> users. But I can only recommend taking the time to learn how to use
> >>> flowViz to anyone looking for Linux based Flow-software.
> >>>
> >>> Thanxs,
> >>>
> >>> Anja
> >>>
> >>>   
> >>>
> >>> ------------------------------------------------------------------------
> >>>
> >>>
> >>> ------------------------------------------------------------------------
> >>>
> >>>
> >>> ------------------------------------------------------------------------
> >>>
> >>> ------------------------------------------------------------------------
> >>>
> >>> _______________________________________________
> >>> Bioconductor mailing list
> >>> Bioconductor at stat.math.ethz.ch
> >>> https://stat.ethz.ch/mailman/listinfo/bioconductor
> >>> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
> >>>       
> >>     
> 
-- 

Anja Schiel, PhD
Department of Anatomy
Institute of Basic Medical Sciences
University of Oslo
Po-Box 1105 Blindern
N-0317 Oslo

Domus Medica
Room 2362
Tel: +47-22851215

http://www.uio.no/sok?person=anjasc



More information about the Bioconductor mailing list