r - How to display only integer values on an axis using ggplot2 - Stack Overflow

PHOTO EMBED

Mon Mar 15 2021 13:34:36 GMT+0000 (Coordinated Universal Time)

Saved by @nofacetou

integer_breaks <- function(n = 5, ...) {
fxn <- function(x) {
breaks <- floor(pretty(x, n, ...))
names(breaks) <- attr(breaks, "labels")
breaks
}
return(fxn)
}

q + geom_bar(position='dodge', colour='black') + 
scale_y_continuous(breaks = integer_breaks())
content_copyCOPY

ggplot2 轴上用整数

https://stackoverflow.com/questions/15622001/how-to-display-only-integer-values-on-an-axis-using-ggplot2