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

label_number(accuracy=) generating plots with multiple 0 values on the X axis #444

Closed
Ali-Hudson opened this issue Jul 25, 2024 · 2 comments

Comments

@Ali-Hudson
Copy link

Ali-Hudson commented Jul 25, 2024

I was using label_number(accuracy=N) to manipulate my X-axis, because I wanted to reduce the number of labels and squeeze the plots into a small space without crowding the axis. I'm finding that this results in multiple 0 values on my X axis for some data, and I have no idea why. The labels don't reflect the expected range I get when I remove the accuracy statement.

Here is a closeup of one facet of the plot to show the problem:

Screenshot 2024-07-25 at 16 35 59

here is a screenshot of a plot made with the same data but without the accuracy statement:
Screenshot 2024-07-25 at 16 45 16

plot<-ggplot(allchr, aes(x=total_change, colour=intro)) +
    geom_density(adjust=5) +  facet_grid(~INT ~POP) +
    xlab("2013-18") + theme_bw() + theme(legend.position="none") +
    geom_vline(data = cutoffs, aes(xintercept = upper975)) +
    geom_vline(data = cutoffs, aes(xintercept = lower975)) + 
    scale_colour_manual(values=river_colours) + 
    scale_x_continuous(labels = label_number(accuracy = 0.5))

If I remove the accuracy statement and just leave it as label_number(), I get a sensible axis but it's far too crowded by default.

Can anyone suggest what might be going on?

@joranE
Copy link

joranE commented Jul 25, 2024

The accuracy argument only controls the precision with which the same set of tick labels are displayed. So setting accuracy = 0.5 is still going to generate breaks at -0.25, 0 & 0.25, but only display the number at a resolution of 0.5, hence all three are rounded to 0.

If you want to change the actual breaks in the axis, that should be done with the breaks argument of scale_x_continuous, not the labels argument.

@Ali-Hudson
Copy link
Author

Ah! Thank you!

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