RGLab / ggcyto

Visualize Cytometry data with ggplot2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ggcyto fill and legend behavior dysfunctional

rwbaer opened this issue · comments

@jacobpwagner
For reference to apparently a similar problem, see your .md file where it is claimed fills will appear but they do not.
See figures 5th & 6th figure at the link below:
[(https://github.com/RGLab/ggcyto/blob/master/vignettes/ggcyto.flowSet.md)]

In creating ggcyto figure, certain forms of faceting produces plots that are expected to have a legend but do not produce one. Further, when using geom_gate() on a 1D figure, The fill on the figure disappears.

Experimentation (well the experimentation failed and serendipity actually was key :-) shows that the problem(s) can be worked around by adding a theme(complete = TRUE) if that helps to figure out the root problem.

Here is a complete example. This may be related to the marginally reproducible issue #84, but I have not yet had a chance to do any complete testing.

Here is a reproducible example that also demonstrates the workaround:

# Legend and fill issues with ggcyto
library(openCyto)
library(ggcyto)
# A reproductible test gating set
data(GvHD)
fs <- GvHD[subset(pData(GvHD), Patient %in%5:7 & Visit %in% c(5:6))[["name"]]]

# transform
tf <- transformList(colnames(fs[[1]])[3:6], asinh, transformationId="asinh")
fs_trans<-transform(fs,tf)
gs <- GatingSet(fs_trans)

# Add a gate
chnl <- "FL1-H"
minden <- openCyto:::.mindensity(fs[[1]], channels = chnl)

ggplot(gs, subset = "root", aes(x = `FL1-H`, fill = name)) + geom_density(alpha = 0.2)

# Note that the expected legend is missing
p <- ggcyto(gs, aes(x = `FL1-H`), subset = "root") + 
  geom_density(aes(fill = Visit), alpha = 0.1) +
  facet_wrap(NULL)
p 

# Add a gate and the fill disappears too
p+ geom_gate(minden)

# The workaround is to add a complete theme
# The fill and missing legend return
p + theme(complete = TRUE)
p+ theme_gray()