Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra.vars functionality a la dittoSeq #20

Open
j-andrews7 opened this issue Jul 8, 2024 · 4 comments
Open

extra.vars functionality a la dittoSeq #20

j-andrews7 opened this issue Jul 8, 2024 · 4 comments

Comments

@j-andrews7
Copy link
Contributor

This functionality is convenient in a lot of ways. Looking at dittoSeq, the data collection is pretty complicated. I haven't toyed with it here, but I assume it'd just be tweaking the .data_adjust_scatter function to pop them on as well.

I know one can use data.out to get the full data, but it being embedded in the plot object was handy in its own way.

@dtm2451
Copy link
Owner

dtm2451 commented Jul 9, 2024

It already works to where every column is kept, and embedded:

example("dittoExampleData", echoe = FALSE)
scatterPlot(example_df, "gene1", "gene2", size = 2) + facet_grid(subcategory~category)

image

But I've found with real data that there can be a LOT of lag from the complete lack of data trimming in scatterPlot and yPlot, so I agree that an extra.vars equivalent (maybe called extra.cols, maybe unchanged) is needed along with trimming of the unused columns.

@j-andrews7
Copy link
Contributor Author

I may just be a dunce with ggplot, but it took me a second to figure out how the data can be accessed from the plot object itself, e.g.

p <- scatterPlot(example_df, "gene1", "gene2", size = 2)

I tried a few approaches before finding the appropriate ones:

> p$data
list()
attr(,"class")
[1] "waiver"

> pg <- ggplot_build(p)
> pg$data
           x        y PANEL group shape colour size fill alpha stroke
1   2.000000 4.954196     1    -1    16  black    2   NA     1    0.5
2   2.000000 5.169925     1    -1    16  black    2   NA     1    0.5
3   2.807355 5.087463     1    -1    16  black    2   NA     1    0.5
4   3.584963 4.954196     1    -1    16  black    2   NA     1    0.5
...

> p$plot_env$Target_data
# Full df

> p$plot_env$p$layers[[1]]$data
# Full df for specific layer

Just commenting this here for my own sake.

@dtm2451
Copy link
Owner

dtm2451 commented Jul 11, 2024

mmmm, this still gives me more inspiration lol

I suppose there could be some increased consistency over whether the plot is given a default p$data, i.e. ggplot(<data_given>) versus only the geoms receiving data via equivalent of ggplot(...) + geom_<whatever>(<data_given>)...

The faceting in my example worked because it operates on the plot layers, but there could be some default data setup picked for all plots that is given in the top-level call, ggplot(), to allow easier addition of new stats or geoms! Currently, I expect that works for some functions, but that you'd need to fish out the data from a certain layer as you do here, then give it to your geom_<whatever> or stat_<whatever> to add another geom onto a scatterPlot()

@j-andrews7
Copy link
Contributor Author

Yeah, in my case, I was trying to use it for plotly stuff downstream, so when do.hover=TRUE, the way to access is data <- plotly_data(p).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants