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

y-position of points created with gghalves::geom_half_point() is variable #26

Open
alesantuz opened this issue Sep 11, 2023 · 6 comments · May be fixed by #27
Open

y-position of points created with gghalves::geom_half_point() is variable #26

alesantuz opened this issue Sep 11, 2023 · 6 comments · May be fixed by #27

Comments

@alesantuz
Copy link

alesantuz commented Sep 11, 2023

Windows 10 x64, build 19045, x86-64 machine
R version 4.3.1 (2023-06-16 ucrt)

As per title, when plotting individual data points with gghalves::geom_half_point(), the y-position of the points changes at every run, especially when the data set is very small.

MRE:

ggplot2::ggplot(iris, ggplot2::aes(x = Species, y = Petal.Width, fill = Species)) + 
    gghalves::geom_half_point()

Another reproducible example, where the error is amplified by the small data set:

data <- data.frame(
  group = c("1", "2", "2", "1", "2", "2", "2", "2"),
  value = c(0.526, 0.473, 0.505, 0.508, 0.505, 0.488, 0.47, 0.499)
)

ggplot2::ggplot() +
  gghalves::geom_half_point(
    data = (data),
    ggplot2::aes(
      x = .data[["group"]],
      y = .data[["value"]]
    )
  )
@alesantuz
Copy link
Author

Is there any update on this issue? I add here a similar MRE as the above, with a couple of pictures:

data <- data.frame(
  group = c("1", "2", "2", "1", "2", "2", "2", "2"),
  value = c(0.526, 0.473, 0.505, 0.508, 0.505, 0.488, 0.47, 0.499)
)

ggplot2::ggplot() +
  ggplot2::coord_cartesian(ylim = c(0.45, 0.55)) +
  gghalves::geom_half_point(
    data = (data),
    ggplot2::aes(
      x = .data[["group"]],
      y = .data[["value"]]
    )
  ) +
  gghalves::geom_half_boxplot(
    data = (data),
    ggplot2::aes(
      x = .data[["group"]],
      y = .data[["value"]]
    )
  )

In the following screenshots it is possible to see that the position of the individual data points is wrong and changes with every run, especially when there are only few points:

image
image

@erocoar
Copy link
Owner

erocoar commented Apr 30, 2024

@alesantuz Apologies for the long silence- it's difficult when life gets in the way. I promise to review this over the next few days 😊

@alesantuz
Copy link
Author

Thanks @erocoar!

@aboggio-pasqua
Copy link

Hi @erocoar! Any update on this issue? I have exactly the same problem... Thanks 😊

@Neurarian
Copy link

This happens due to position_jitter() jittering both vertically and horizontally by default. You can avoid this by supplying transformation = position_jitter(height = 0) to the transformation argument of the geom_half_point() function instead of relying on the default.

data <- data.frame(
  group = c("1", "2", "2", "1", "2", "2", "2", "2"),
  value = c(0.526, 0.473, 0.505, 0.508, 0.505, 0.488, 0.47, 0.499)
)

ggplot2::ggplot() +
  gghalves::geom_half_point(
    data = (data),
    transformation = ggplot2::position_jitter(height = 0),
    ggplot2::aes(
      x = .data[["group"]],
      y = .data[["value"]]
    )
  )

If jittering in y should not occur by default, I could open a pull request and set height = 0 as a more sensible setting.

@alesantuz
Copy link
Author

Thank you very much @Neurarian! Yeah, I really think it shouldn't happen by default, as we aim to show the true values here, not random dots. And I agree that height = 0 seems like a sensible default.

@Neurarian Neurarian linked a pull request Nov 27, 2024 that will close this issue
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 a pull request may close this issue.

4 participants