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

geom_point() and geom_jitter(width = 0, height = 0) have different behaviors for zero values in scale_y_log10() #4790

Closed
iamstein opened this issue Apr 1, 2022 · 1 comment · Fixed by #4933
Labels
bug an unexpected problem or unintended behavior positions 🥇

Comments

@iamstein
Copy link

iamstein commented Apr 1, 2022

I'm using ggplot2 3.3.5 and found that geom_point() and geom_jitter(height = 0, width = 0) have different behaviors for dealing with zero values in log-transformed axes. In particular, geom_point() represents zeros as dots lying on the x-axis whereas geom_jitter() does not plot the zeros at all. For me, this is relevant, because sometimes I want the jitter width to be non-zero, but height to be zero, and I don't want my dots to disappear! Right now I work around the issue by setting the zeros to some small value I choose to make the plot nice.

data = data.frame(x = c(0, 0, 1, 1, 2, 2), y = c(0, 0, 0, 1, 2, 3))
ggplot(data, aes(x = x, y = y)) + geom_point() + scale_y_log10()
ggplot(data, aes(x = x, y = y)) + geom_jitter(height = 0, width = 0) + scale_y_log10()

image

@iamstein iamstein changed the title geom_point() and geom_jitter(width = 0, height = 0) have different behaviors 0 values in scale_y_log10() geom_point() and geom_jitter(width = 0, height = 0) have different behaviors for zero values in scale_y_log10() Apr 1, 2022
@yutannihilation
Copy link
Member

Thanks. it seems jitter calculates -Inf for -Inf value, accordingly, -Inf - (-Inf) results in NaN. We can check if the value is infinite and skip jittering.

fixed_jitter <- with_seed_null(params$seed, transform_position(dummy_data, trans_x, trans_y))
x_jit <- fixed_jitter$x - x
y_jit <- fixed_jitter$y - y

@hadley hadley added bug an unexpected problem or unintended behavior positions 🥇 labels Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior positions 🥇
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants