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

Plot proportion of cells per level as label #54

Closed
hummuscience opened this issue Jun 9, 2020 · 8 comments
Closed

Plot proportion of cells per level as label #54

hummuscience opened this issue Jun 9, 2020 · 8 comments
Labels
question Further information is requested

Comments

@hummuscience
Copy link

I was wondering how I could plot a label that contains the proportion of cells in the current cluster by resolution/clustering depth.

@lazappi lazappi added the question Further information is requested label Jun 10, 2020
@lazappi
Copy link
Owner

lazappi commented Jun 10, 2020

Hi @Cumol

Thanks for giving {clustree} a go! If I am understanding you correctly you want to add a label with the proportion of the total samples that belong to each cluster (something like cluster_size / total_samples)? Every sample should be present at each resolution so total_samples should be the same whichever resolution you look at.

This sounds like something that should be easy to do but unfortunately I don't think that it is possible at the moment. It is easy to add the cluster size as a label:

clustree(iris_clusts, prefix = "K", node_label = "size")

But I don't think it is possible to do a proportion due to the way the node aggregation functions work. I think I might have a way to make this possible but I need to try some things and see if they work. I will comment here if I am able to come up with a solution.

Thanks for raising the issue 🎉! I hadn't considered this a problem before and I think it's functionality we should have 😸.

@hummuscience
Copy link
Author

Thanks for the quick reply!

I found the solution for "size" and if I understood correctly, "size" is calculated internally, which is why you can pass it as a node label. I was wondering whether the total_samples is also calculated internally and it would be possible to do node_label = "size/total_samples".

Or allow general access to "resolution statistics". I saw another issue where someone calculated the statistics beforehand and then added the values where needed, but that looked too complex for me :D

@lazappi
Copy link
Owner

lazappi commented Jun 10, 2020

Yeah, unfortunately that won't work the way things are set up at the moment. I think the workaround I have thought will make that possible but I will have to try and implement it to see.

@lazappi
Copy link
Owner

lazappi commented Jun 12, 2020

Ok, my solution didn't work quite as well as I had hoped but I have come up with a slightly hacky workaround for your specific case. Try something like this and see if it gives you what you want.

# You need to replace 150 here with however many samples you have
# I think the only way to do this is to hard code it for now
prop_samples <- function(x) {length(x) / 150}

clustree(YOUR_DATA, prefix = "YOUR_PREFIX", node_label = "ANY_METADATA_COLUMN", 
         node_label_aggr = "prop_samples")

@hummuscience
Copy link
Author

Will give it a try and let you know.

@lazappi
Copy link
Owner

lazappi commented Jul 13, 2020

@Cumol Was this helpful in the end?

@lazappi lazappi closed this as completed Jul 27, 2020
@plijnzaad
Copy link

I'm not Cumol but yes this works very nicely, I'm using , node_label_aggr='n_cells', with
n_cells <- function(x)sprintf("%g cells (%.1f%%)", length(x), 100*length(x)/nrow(df))
where df is the data.frame that is fed to clustree. Many thanks!

PS: I was hoping to be able to say edge_color="black" (it confuses my users) but that doesn't work for some reason?

@lazappi
Copy link
Owner

lazappi commented May 2, 2023

PS: I was hoping to be able to say edge_color="black" (it confuses my users) but that doesn't work for some reason?

Please open a new issue if this is a feature you would like to have. At the moment there is no parameter for controlling the edge colour.

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

No branches or pull requests

3 participants