Closed malisas closed 6 years ago
a minimum reproducible and self-contained example (with data) would be helpful for troubleshoot
Hi Mike, here is a reprex. I will send you the GatingSet privately again.
In the meantime, do you have an opinion about whether it is safe to use getPopStats()
?
library(openCyto)
#> Loading required package: flowWorkspace
#> Loading required package: flowCore
#> Loading required package: ncdfFlow
#> Loading required package: RcppArmadillo
#> Loading required package: BH
library(ggcyto)
#> Loading required package: ggplot2
gs <- load_gs("/path/to/20181023_GS_For_Reprex_small")
#> loading R object...
#> loading tree object...
#> Done
gs
#> A GatingSet with 1 samples
plot(gs, bool = T, fontsize = 15)
pnts <- matrix(c(1788.51407984939, 3222.9862729063, 3407.84093696002, 1917.912344687, 1773.7257067251, 1784.81698656832,
2205.12898496853, 3554.98324124303, 3241.06364676059, 1958.47787501804, 1868.78656230877, 2205.12898496853),
ncol = 2)
colnames(pnts) <- c("<R660-A>", "<G610-A>")
my_polygon_gate <- polygonGate(.gate = pnts, filterId="My_Diagonal")
parent_pop <- "/Live CD3+/CD14-19-/Singlet/CCR7 Keeper/MR1 Keeper/Lymphocytes"
add(gs, my_polygon_gate, parent = parent_pop, name = "new_gate")
#> replicating filter 'My_Diagonal' across samples!
#> [1] 14
recompute(gs, parent_pop)
#> .
#> done!
ggcyto(gs,
subset = parent_pop,
aes(x = `<R660-A>`, y = `<G610-A>`)) +
geom_hex(bins = 120) + geom_gate("new_gate") +
geom_stats() +
xlim(c(1400,3800)) + ylim(c(1400, 4000)) +
geom_polygon(as.data.frame(my_polygon_gate@boundaries),
mapping = aes(x = `<R660-A>`, y = `<G610-A>`),
colour = "black", fill = NA)
#> Warning: Removed 49948 rows containing non-finite values (stat_binhex).
#> Warning: Removed 4 rows containing missing values (geom_hex).
Created on 2018-10-23 by the reprex package (v0.2.1)
Update:
geom_overlay()
seems to match the geom_polygon()
events, so I feel like it is probably safe to use getPopStats()
.
The location of the red geom_gate()
gate changes depending on how I resize RStudio's plot window. Here's another version from when I resized the window a little.
And from using the png()
function instead of exporting manually:
I did try to reproduce this problem using some of the data from the flowWorkspaceData
package, but the code worked correctly (i.e. no inconsistencies) on the T-cell and gs_bcell_auto datasets.
Yes, you are right. The gate and stats are computed correctly in GatingSet
,it is the artifact from ggcyto
which has to do with #5, basically it is the unsolved problem of plotting polygon with ggplot where it loses its shape as you start to setting limits on axis.
I need to think it over before coming up a better solution.
I've switched from scale
to coord_cartesian
limits , which won't clip the data as you zoom in by setting limits
through coord_cartesian
instead of the xlim/ylim
directly.
p + coord_cartesian(xlim = c(0,4e3), ylim = c(0,4e3))
p + coord_cartesian(xlim = c(2.5e3,4e3), ylim = c(1e3,4e3))
I've tested it and it works pretty well except for some legacy quadrant gates, where the gate coordinates were extended to far right and thus exaggerates the space for hexbin
. Even if limits
are set through coord_cartesian
, hexbin
is stilled computed on the original large coord
space. So we will have to figure out how to fix this before merging coord_cartesian
branch to trunk
Thanks, Mike. Works for me.
I will use the coord_cartesian
branch with ggplot2::coord_cartesian()
(and not ggplot2::xlim()
or ggplot2::ylim()
) anytime I wish to use geom_gate()
with a polygon gate.
@malisas , I've addressed geom_hex
issue by 2974b47506b4ac9bd19715d95d752d863cddbe23 and coord_cartesian
branch is now merged to trunk
and will be hopefully applied to bioc release once it is stabilized.
Hi, as shown below, visualizing a
polygonGate
usinggeom_gate()
andgeom_polygon()
is not consistent. Thegeom_polygon()
shape accurately reflects the shape I originally drew and intended, butgeom_gate()
does not.While this is being investigated, my question is:
Do you think it is safe to trust the results of
getPopStats(gs, subpopulations = "new_gate")
?Basically, I want to know if this is just a visualization error or if the gate membership is also calculated incorrectly. If it's just the visualization, I will go ahead and use
getPopStats()
andgeom_polygon()
for my analysis.Thanks.
(I recently experienced another visualization issue, but I don't know if it's related)