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

Gate annotation in DensityScatterPlot #75

Merged
merged 20 commits into from
Mar 3, 2025
Merged

Conversation

stefanppetkov
Copy link
Collaborator

@stefanppetkov stefanppetkov commented Feb 13, 2025

Description

This PR improves gate annotations in density scatter plots and introduces a new gate type. The changes include:

  1. Gate Annotation Improvements
  • Added support for customizable annotation parameters through a list of arguments passed to geom_text
  • Users can now control annotation aesthetics such as:
    • Text color
    • Font size
    • Font face
    • Other text-related parameters supported by geom_text
  1. New Feature: Quadrant Gates
  • Added support for quadrant gates in density scatter plots

Fixes: TECH-228

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

The changes have been tested with the following test cases:

  1. Gate Types:

    • Rectangle gates (single and multiple)
    • Quadrant gates (single and faceted)
    • Testing gate parameters with different data ranges
    • Verifying error handling for invalid gate types
  2. Gate Annotation Parameters:

    • Testing default annotation appearance
    • Customizing annotation aesthetics
    • Verifying error handling for invalid annotation parameters

PR checklist:

  • This comment contains a description of changes (with reason)
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and documentation and corrected any misspellings
  • I have run R CMD check on the package and it passes without errors or warnings
  • I have documented any significant changes to the code in CHANGELOG.md

@stefanppetkov stefanppetkov marked this pull request as draft February 13, 2025 11:48
@stefanppetkov stefanppetkov marked this pull request as ready for review February 16, 2025 18:42
Copy link
Collaborator

@ludvigla ludvigla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, but I will try it out on some examples to get a feel for how to use these additions

Copy link
Collaborator

@ludvigla ludvigla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some minor edits to the code (updated assertions and applied our styling) but everything seems to work as expected.

I know that multiple people have worked on this function now but if there's anything I'd ask for (if time allows) would be to refactor parts of the code into smaller parts and document some of the more complicated steps. Right now it's quite complicated to follow. For example, the code to create density_plot_x and density_plot_y is virtually the same except for a coord_flip(). This code could be wrapped in a small internal function.

@stefanppetkov
Copy link
Collaborator Author

I know that multiple people have worked on this function now but if there's anything I'd ask for (if time allows) would be to refactor parts of the code into smaller parts and document some of the more complicated steps. Right now it's quite complicated to follow. For example, the code to create density_plot_x and density_plot_y is virtually the same except for a coord_flip(). This code could be wrapped in a small internal function.

Thanks for taking the time to go through it. I completely agree that the code can be a bit hard to follow at times.

I am considering to just delay merging this a bit to try and refactor the code. This is important functionality that we will likely expand on so maintainability/readability is important.

Copy link
Contributor

@maxkarlsson maxkarlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment to add on the documentation :)
Otherwise I agree with Ludvig that a refactorization would do wonders for this function.

#' @param marker1 Name of first marker to plot.
#' @param marker2 Name of second marker to plot.
#' @param facet_vars Optional character vector of length 1 or 2 specifying variables to facet by.
#' @param plot_gate Optional data frame containing gate parameters. If provided, `gate_type` must also be specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to specify the format of the plot_gate either here or in a details section below. This information should be provided somewhere:

A data frame with columns 'xmin', 'xmax', 'ymin', 'ymax' to plot a gate. This data frame can also contain the variables in 'facet_vars' to plot different gates in different facets.

Would also be important to specify the format of plot_gate if gate_type = "quadrant"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expanded the documentation for plot_gate to specify the format of the dataframe.

Also split up the function into a few parts and wrapped them in internal functions, which should make the code easier to follow (I hope).

Copy link
Collaborator

@ludvigla ludvigla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work. It's much easier to follow now!

I just had one comment on the assertions that should be fixed.

Copy link
Contributor

@maxkarlsson maxkarlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just add the expect_MASS utility function please.

Comment on lines 509 to 522
gate_data <- gate_data %>%
group_by(!!!syms(facet_vars)) %>%
group_modify(function(.x, .y) {
# Get the current facet's data by filtering based on group keys
current_data <- if (!is.null(facet_vars)) {
filter_conds <- lapply(facet_vars, function(var) {
facet_var <- sym(var)
quo(!!facet_var == .y[[var]])
})
plot_data %>%
filter(!!!filter_conds)
} else {
plot_data
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a bit difficult to follow, but as long it works all is good!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few intermediate steps which can be skipped. I refactored this part.

Copy link
Collaborator

@ludvigla ludvigla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Copy link
Contributor

@maxkarlsson maxkarlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, well done!

@stefanppetkov stefanppetkov merged commit 87dcfb4 into main Mar 3, 2025
7 checks passed
@stefanppetkov stefanppetkov deleted the feature/tech-228 branch March 3, 2025 14:49
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

Successfully merging this pull request may close these issues.

3 participants