Open sapirhv opened 1 year ago
@sapirhv, there are a couple of issues with your code example. Variables with dots in their name must always be wrapped in backticks for ggplot and the color
aesthetic is the one to modify for geom_point()
. The correct code would look something like this:
p <- ggcyto(fs, aes(x = `Median.var1`, y = `Median.var2`)) +
geom_point(aes(color = `Median.var3`)) +
labs(x = "Median Intensity - var1",
y = "Median intenisty - var2") +
ggtitle("var1 vs var2- Median")
However, if you run that code you will encounter another issue which points out that Median.var3
doesn't exist. This is because ggcyto
only exposes the columns used for the xy axes to ggplot
(to conserve memory) and so ggplot
does not have access to Median.var3
. If you re only plotting a single sample, a simple workaround would be to extract the data manually and pass it ggplot
directly:
# extract data
exprs <- as.data.frame(exprs(fs[[1, c("Median.var1", "Median.var2", "Median.var3")]]))
# plot using ggplot
ggplot(exprs, aes(x = `Median.var1`, y = `Median.var2`, color = `Median.var3`)) + geom_point()
Perhaps @mikejiang has a better solution. The problem is that we can't append columns on the fly as new geoms
are added, so I think if we wanted to make this work we'd have to make ggcyto
expose all the (relevant) columns to ggplot
- which would have significant memory implications. @mikejiang would it be possible to capture all variables mentioned within the top-level ggcyto aes()
and expose those to ggplot? Then perhaps the following code could work:
# fortify need to include all three columns
p <- ggcyto(fs, aes(x = `Median.var1`, y = `Median.var2`, color = `Median.var3`)) +
geom_point()
We could check all mapping values against the colnames
or markernames
of the flowSet
and append them to the dims
here:
https://github.com/RGLab/ggcyto/blob/95559e8ea56bcc8d710628bd457d975f94ab8383/R/ggcyto_flowSet.R#L20
I'd be happy to put together a PR for this, if you think it could work.
Thanks a lot for the swift reply!! unfortunately I cannot use ggplot in this case since I require gating, which is also done in this code in a late stage, something ggplot is having a very hard time with (and is also the reason i used ggcyto in the first place) do you know of a way to resolve this? Thanks again!
when using ggcyto, the "fill" function of ggplot does not work. It's not recording the variable in "fill" and indicating that it's not found resulting in an error. sample code:
sample error: