Skip to content

Adding 2 possible quantile dot plot functions #357

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

behramulukir
Copy link
Collaborator

@behramulukir behramulukir commented Jun 20, 2025

As I mentioned at #354 I have been working on adding quantile dot plots. It was more complicated than I was expecting, so I wanted to make sure about the direction of this.

Current Progress

So far, I have implemented two functions, ppc_qdotplot which under the hood utilises geom_dotplot and ppc_qdotplot_ggdist which utilises stat_dots from ggdist.

qdotplot

This function utilises geom_dotplot, which gives a very simple way to build dot plots. geom_dotplot function has two main deficiencies:

  1. Very often, the number of dots exceeds the space that the graphic has, and since geom_dotplot doesn't have a proper auto-sizing for dots, the visual is getting clipped and not presenting the full picture.
  2. It doesn't have functionality to plot according to quantiles.

To minimise the first problem, I implemented a simple auto-sizing algorithm which performs well when the bin width is not specified or very reasonably specified; however, when it is even a little unsuitable, it is likely to run into issues. Here are some example uses of ppc_qdotplot:

color_scheme_set("brightblue")
y <- example_y_data()
yrep <- example_yrep_draws()
group <- example_group_data()
ppc_qdotplot(y, yrep[1:8, ])

plot1

ppc_qdotplot(y, yrep[1:8, ], binwidth = 5)

plot2

ppc_qdotplot(y, yrep[1:8, ], binwidth = 3)

plot6

ppc_qdotplot(y, yrep[1:8, ], binwidth = 10)

plot3

As you can see, for certain bin widths, dots are over-compressed or exceed the limit of the graphic.

qdotplot_ggdist

The second alternative relies on stat_dots from ggdist. It is slightly more successful overall in handling edge cases and has a warning system; however, it also brings additional dependency to the package, making me unsure if we want to go that route. The advantages of this over qdotplot are:

  1. When dots are unfit for the graph size, it gives a warning to the user
  2. It can plot based on quantiles
ppc_qdotplot_ggdist(y, yrep[1:8, ])

plot4

ppc_qdotplot_ggdist(y, yrep[1:8, ], binwidth = 3)

plot7

ppc_qdotplot_ggdist(y, yrep[1:8, ], binwidth = 5)

plot5

ppc_qdotplot_ggdist(y, yrep[1:8, ], binwidth = 10)

plot8

In the previous three graphics where the dots do not fit into the visual, the following error is thrown at the console:

Warning messages:
1: The provided binwidth will cause dots to overflow the boundaries of the geometry.Set `binwidth = NA` to automatically determine a binwidth that ensures dots fit within the bounds,
→ OR set `overflow = "compress"` to automatically reduce the spacing between dots to ensure the dots fit within the bounds,
→ OR set `overflow = "keep"` to allow dots to overflow the bounds of the geometry without producing a warning.

ppc_qdotplot_ggdist can be used with quantiles as follows:

ppc_qdotplot_ggdist(y, yrep[1:8, ], quantile = 25)

plot9

Future

To move forward, I think we need to decide on which function we want to keep and whether we want to add ggdist dependency. After that, I can remove the unnecessary function and continue with the rest of the implementation.

  • implement geom_dotplot version
  • implement stat_dots
  • decide on which function to keep
  • update the documentation
  • implement tests

@behramulukir behramulukir self-assigned this Jun 20, 2025
@behramulukir behramulukir changed the title Adding 2 possible quantile dot plot functions #354 Adding 2 possible quantile dot plot functions Jun 20, 2025
@behramulukir behramulukir linked an issue Jun 23, 2025 that may be closed by this pull request
@jgabry
Copy link
Member

jgabry commented Jun 23, 2025

I didn't realize there would be this sort of difficulty with the dot plots. I think handling those edge cases and having appropriate warnings is probably enough of a benefit to add ggdist dependency and maybe we can also use ggdist for other plots in the future. For now we could just add it to Suggests (instead of Imports) and then use our internal suggested_package() function to make sure it's installed if someone wants to make the dot plots. If we end up using ggdist for a bunch of other plots in the future we can move it to Imports so that it gets automatically installed. @avehtari @TeemuSailynoja what do you think?

@behramulukir
Copy link
Collaborator Author

This solution makes sense to me. If @TeemuSailynoja or @avehtari don't have any objection, I can work on this.

@avehtari
Copy link
Member

I like ggdist, so I'm fine using it more

@TeemuSailynoja
Copy link
Collaborator

I think adding ggdist as a suggested package is very good for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding quantile dot plots to PPC distributions
4 participants