assign the y-scale relation in flowViz densityplot
3
0
Entering edit mode
peterfoster ▴ 20
@peterfoster-7470
Last seen 8.5 years ago
United States

I'm using the densityplot function in flowViz to plot various channels of a flowSet.

densityplot(~., fs.gated.1, channels=c("deflog.V1", "deflog.Y2"), 
            margin=FALSE, col="black")

How can I set the y-scale to be the same across all of the samples/flowframes?  ylim sets the entire plot window, not the trace heights.  I dug around in the lattice/xyplot/trellis options to try to find something there, but nothing worked.  the "relation" option in "Common bivariate trellis plots"...

relation
A character string that determines how axis limits are calculated for each panel. Possible values are "same" (default), "free" and "sliced". For relation="same", the same limits, usually large enough to encompass all the data, are used for all the panels. For relation="free", limits for each panel is determined by just the points in that panel.

...appears to be exactly what I want (e.g. relation="same"), but this has no apparent effect on the densityplot function.  Perhaps this is not an issue of axis scaling, but something in the way the density function is calculated and normalized?

Suggestions?

flowviz densityplot • 2.7k views
ADD COMMENT
0
Entering edit mode
Jiang, Mike ★ 1.3k
@jiang-mike-4886
Last seen 2.5 years ago
(Private Address)

This should do the job

library(flowViz)
data(GvHD)
fs <- GvHD[1:5]
densityplot(~., fs, channels = c("FSC-H", "FL2-H") ,scales = list(x = list(relation = "same")))
ADD COMMENT
0
Entering edit mode

Seeing your syntax for this was informative for me, but ultimately this did not change the way the y-axis (or x, as you had typed) is plotted for each dataset in the flowframe.  This appears to affect how the plot window for the two channels are treated, not the y-scale for the individual traces within each panel.  In addition to "scales", I also tried as many alterations of limits, y, ylim, and prepanel, that I could think of.  Nothing seems to change the ylim of the individual traces... only the channel-wide plot panel containing data from all flowframes of the set.
 

ADD REPLY
0
Entering edit mode

Can you try this very example code? Because it did it for me. Also I am confused that you kept saying y-axis since in densityplot y-axis is simply the sample name and doesn't seem to be relevant to what you are talking about here.

ADD REPLY
0
Entering edit mode

Thank you for your example, I did try it and play with it in an attempt to achieve my aims...
As a density plot (i.e. histogram) the y-axis to which I refer is the event count at each value of x.  Yes, your example rescales the x axis, but leaves the y axis of each trace untouched, having a default of normalizing for each sample (row).  In short, if you set overlap=0, you'll notice that every sample is scaled to the maximum row height (y-axis), regardless of the number of counts in that sample.  Said another way, if two of your samples were simply a set of normally distributed values with n=100 and n=10,000, they would would appear exactly the same if plotted with this function.  I wish to be able to distinguish these differences in population size by fixing the y-axis (event counts) for all samples plotted.

ADD REPLY
0
Entering edit mode
Jiang, Mike ★ 1.3k
@jiang-mike-4886
Last seen 2.5 years ago
(Private Address)

`densityplot` is based on `stats::density`(i.e. `kernel density estimation`). That said, it is not histogram and y-axis is not counts but the `proportion`.

 

ADD COMMENT
0
Entering edit mode

It is not clear in the default `stack` mode, but you can see the actual `y-axis` by plotting it in the `non-stack` mode. e.g

densityplot(~`FSC-H`, fs, stack = FALSE)

 

ADD REPLY
0
Entering edit mode

Is there some simple way to turn it into counts instead of a proportion?
 

ADD REPLY
0
Entering edit mode

It is very easy to do so in "ggcyto" (which will deprecate lattice-based "flowViz" eventuall). Simply specify 'type' in 'geom_stats' layer, e.g.

p + geom_stats(type = "count")
ADD REPLY
0
Entering edit mode

Thank you very much! If anyone is interested, here's how I went about it in 'base R' using 'density', seems valid to me:

dat <- exprs(x[,'GFP-H'])  # extract the numbers for GFP from flowframe 'x'
dens <- density(dat, bw=0.1)  # fixed bandwidth for direct comparison of different samples
dens$y <- dens$n*dens$y/sum(dens$y)  # turn the proportions into counts
plot(dens)  # plot the results, and if desired, repeat for other samples 
ADD REPLY
0
Entering edit mode

Sorry, I misunderstood your intention. I though you wanted to change `stats` displayed in gate area instead of the y variable.

Again, it is fairly straightforward with ggcyto

> p <- ggcyto(fs, aes(x = `FSC-H`))
> p + geom_density() ##density on y axis
> p + geom_density(aes(y = ..count..)) #count on y axis
ADD REPLY
0
Entering edit mode
magomudw • 0
@magomudw-9280
Last seen 8.3 years ago

Have been analysing my flow data using flowJo but then l would want to use R and its packages. Could l have someone who could flow analysis using flow workspace and other related packages...., Greg or anyone? we can chat more using my email...., magomudw@gmail.com

 

ADD COMMENT

Login before adding your answer.

Traffic: 851 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6