坐山雕

导航

ggplot2: display every nth value on discrete axis

every_nth = function(n) {
return(function(x) {x[c(TRUE, rep(FALSE, n - 1))]})
}

ggplot(mpg, aes(x = class, y = cyl)) +
geom_point() +
scale_x_discrete(breaks = every_nth(n = 3))

https://stackoverflow.com/questions/52919899/ggplot2-display-every-nth-value-on-discrete-axis

posted on 2021-05-07 20:12  坐山雕  阅读(41)  评论(0编辑  收藏  举报