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

testing that two ggplots are the same #98

Closed
jgabry opened this issue Dec 10, 2020 · 3 comments
Closed

testing that two ggplots are the same #98

jgabry opened this issue Dec 10, 2020 · 3 comments

Comments

@jgabry
Copy link

jgabry commented Dec 10, 2020

This is a follow up to r-lib/waldo#56, which made more sense to ask here than in the waldo repo.

Currently vdiffr::expect_doppelganger() accepts a single ggplot object as input and compares to an SVG, but is there a way (or would you consider adding a way) to use vdiffr to test that two ggplot objects correspond to the same looking plot? I guess that would require either comparing them both to the same saved SVG or comparing separate SVG files created for each plot to each other.

Here's one example of a use case: in the bayesplot package we want to test that two different plotting functions create the same ggplot in the special case where the input matrix has 1 row:

# with exactly 1 row in `yrep` matrix these should produce the same plot
plot1 <- ppc_scatter_avg(y, yrep[1,, drop=FALSE])
plot2 <- ppc_scatter(y, yrep[1,, drop = FALSE])

Is there a recommended way of using vdiffr to compare plot1 to plot2 or, if not, would you consider supporting this?

Thank you!

@lionel-
Copy link
Member

lionel- commented Jun 8, 2021

I don't think this is in scope for vdiffr. The approach seems brittle because the graphics engine might take two plots that look exactly the same but draw them in different ways.

@lionel- lionel- closed this as completed Jun 8, 2021
@jairav
Copy link

jairav commented Apr 5, 2023

@jgabry did you come up with an alternate solution for this?

@shug0131
Copy link

shug0131 commented Mar 5, 2024

A possible way to achieve this is by using the same title argument to expect_doppelganger

fig1<- plot_function1()
vdiffr::expect_doppelganger("plot", fig1)
fig2<- plot_function2()
vdiffr::expect_doppelganger("plot", fig2)

This seems to have the desired behaviour when I run the test. It passes if fig1 and fig2 are the same, and fails if they are different.

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

4 participants