Skip to content

Instantly share code, notes, and snippets.

@jhrcook
Created November 9, 2019 00:26
Show Gist options
  • Save jhrcook/eb7b63cc57c683a6eb4986c4107a88ec to your computer and use it in GitHub Desktop.
Save jhrcook/eb7b63cc57c683a6eb4986c4107a88ec to your computer and use it in GitHub Desktop.
This is how to make the x or y axes only show integer values in a programmatic and scalable fashion.
# A function factory for getting integer y-axis values.
integer_breaks <- function(n = 5, ...) {
fxn <- function(x) {
breaks <- floor(pretty(x, n, ...))
names(breaks) <- attr(breaks, "labels")
breaks
}
return(fxn)
}
plot + scale_y_continuous(breaks = integer_breaks())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment