-
Notifications
You must be signed in to change notification settings - Fork 84
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
fixed byrow=FALSE
reorder not only plots but also labels
#203
base: master
Are you sure you want to change the base?
Conversation
Add the function which reoder the labels when byrow=F
Please consider merging - this seems like a simple and straightforward bugfix. I just ran into this bug in the wild and found it quite surprising. |
# if the user wants to layout the plots by column, we use the calculated rows to reorder plots and labels | ||
if (!isTRUE(byrow)) | ||
plots <- plots[c(t(matrix(c(1:num_plots, rep(NA, (rows * cols) - num_plots)), nrow = rows, byrow = FALSE)))] | ||
labels <- labels[c(t(matrix(c(1:num_plots, rep(NA, (rows * cols) - num_plots)), nrow = rows, byrow = FALSE)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this code block be enclosed in curly braces? Otherwise line 183 gets executed regardless of whether the condition is true or not, no? Either way, please add curly braces for clarity.
Apologies, yes, this is fine in principle. Is it possible to add a simple unit test that tests for the order of the labels in both arrangements? Here is some starting code for the unit tests: p_list <- map(1:3, \(x) ggplot())
g <- plot_grid(plotlist = p_list, ncol = 2, labels = 1:3, byrow = FALSE)
layer_data(g, 4) Just extract all the labels by making the relevant |
@Doubt-0KB I don't know what you did with your last commit but it's not a clean diff. You probably messed up newlines. Please revert. |
Sorry, I'm not familiar with the operation and made a mistake. I will revert and commit again. |
I apologize for the inconvenience caused by my incorrect commit operation. |
|
||
p_list <- lapply(1:3, \(x) ggplot()) | ||
|
||
expect_doppelganger("byrow is TRUE", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No visual tests please. (I meant to say this in my original comment but now reading it again I did not explicitly do so.) Visual tests cause constant headaches, and they get disabled all the time because the false positive rate is so high.
Instead, you can extract the location of the labels using the code I posted (e.g., layer_data(g, 4)
) and check that the labels are placed in the correct location.
This PR fixes an issue where the argument
byrow=FALSE
only reorders the plots, but not the labels. Closes #199.Here is a demo of fixed function.