Created
November 9, 2019 00:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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