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

subplot() fails to plot 6 plots in a 2 rows x 4 columns grid #2400

Open
louievdl opened this issue Nov 1, 2024 · 2 comments
Open

subplot() fails to plot 6 plots in a 2 rows x 4 columns grid #2400

louievdl opened this issue Nov 1, 2024 · 2 comments

Comments

@louievdl
Copy link

louievdl commented Nov 1, 2024

I want to use subplot function to plot 6 ggplots in a 2 rows x 4 columns grid.

Here is a reproducible example:

figlist <- list()
for (i in 1:6) figlist[[i]] <- ggplot(data.frame(a = 1:3,b = 4:6), aes(a,b)) + geom_point()
subplot(figlist, nrows = 2, widths = rep(0.25,4))

This generates "Error: The length of the widths argument must be equal to the number of columns"

Looking into the code of subplots.R, the subplot function accepts arguments nrows, widths and heights, which appear to be passed through to get_domains.

The problem is that get_domains calculates ncols ignoring length(widths) and then generates an error when these don't match.

I would have expected get_domains to calculate ncols only if widths was not supplied.

I hope this helps.

@romanzenka
Copy link

romanzenka commented Nov 8, 2024

I do not think I would want plotly to work the way you envision.

A "principle of least surprise" approach would be to allow the user to set both nrows and ncols (ncols being calculated by default directly in the header of the function), and be able to generate "blank spaces" when there are not enough plots to fill all the slots.

Then if you say ncols=4 and provide 4 widths, it should work.

@louievdl
Copy link
Author

Yes, as you say, probably better to add an ncols option for subplot - if the user didn't provide widths, subplot could just assume equal widths.

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