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

Fix boxplot colour group bug #6

Merged
merged 5 commits into from
Oct 11, 2021
Merged

Conversation

dan-knight
Copy link
Contributor

@dan-knight dan-knight commented Aug 30, 2021

Fixes problem with boxplot points.col in Issue #4 with lattice group/subscript arguments.

@dan-knight dan-knight linked an issue Aug 30, 2021 that may be closed by this pull request
@dan-knight dan-knight marked this pull request as ready for review August 31, 2021 01:29
Copy link
Contributor

@pboutros pboutros left a comment

Choose a reason for hiding this comment

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

Consider adding an example of using the feature

Also, check if any of the bugs are in related functions (create.violinplot, create.stripplot)

pch = points.info$pch,
col = points.info$col,
groups = points.info$groups,
subscripts = if (!is.null(points.info$groups)) subscripts else NULL,
Copy link
Contributor

Choose a reason for hiding this comment

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

will this work with the flow-control {}, so something like { subscripts; } else { NULL; } If so, that's preferred, otherwise all good.

Copy link
Contributor Author

@dan-knight dan-knight Sep 2, 2021

Choose a reason for hiding this comment

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

Consider adding an example of using the feature

Also, check if any of the bugs are in related functions (create.violinplot, create.stripplot)

Related functions (stripplot, violinplot, scatterplot) work when a group variable is passed normally. The boxplot is a slightly different case because it is a combination of two plots, and the groups needed to be handled differently for the stripplot.

Copy link

@alkaZeltser alkaZeltser left a comment

Choose a reason for hiding this comment

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

Does this fix also allow unique text labels to be applied to each panel?
(Trevor attempted this earlier: #5 )

@dan-knight
Copy link
Contributor Author

Does this fix also allow unique text labels to be applied to each panel?
(Trevor attempted this earlier: #5 )

This just fixes the colours. We thought it would be more manageable to put the two features in separate pull requests to begin with.

- Grouping is only needed when the formula contains a conditional split
  (e.g. score ~ sex | gene).

- Passing the colours as the groups argument had inconsistent results.
  Changing the group to use the x column from the given data was
  more stable.

- This required parsing the formula, and works when the data is split
  with |.

- Now does not need a full colour vector to be passed, just a colour
  scheme (though the full vector will also work with unique function).
@dan-knight
Copy link
Contributor Author

I found some inconsistencies when testing this with different datasets. When the formula uses a conditional split (e.g. score ~ sex | gene), the underlying lattice library interprets colour values differently.

For the use case in issue #4, @alkaZeltser used a colour vector the same length as the data, with each colour value corresponding to a specific point. When groups are specified, lattice interprets the colours as a colour scheme, assigning the first 2 colour values to the groups, and ignoring the rest of the vector. This is a problem if, for example, the first two rows of the data happen to be male, both plots will be blue. This is the behaviour of lattice, not BPG. (I tested this with lattice outside of BPG and had the same results.)

blue_bluepink_bluepink_pinkblue_pink

In this case (with a conditional split in the function), the plot should be passed a colour scheme (e.g. points.col = c('pink', 'dodgerblue')) instead of individual values. This is simpler anyway, but I don't want to invalidate the way the library was used before. (I'm sure it can be useful to pass a full colour vector and have control over each point individually.) To account for this, I included a check to see if there a conditional split in the formula, and only used the grouping solution when needed (leaving the functionality for simpler formulas unchanged).

@dan-knight
Copy link
Contributor Author

I think with these approvals, this is ready to merge. This passes R CMD check, and I've also verified test and example output.

@dan-knight dan-knight merged commit 973aa53 into main Oct 11, 2021
@dan-knight dan-knight deleted the danknight-fix-boxplot-colours branch October 18, 2021 21:12
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.

Stripplot color coding bug in create.boxplot
3 participants