不想显示来自ggplot2的所有刻度线的所有标签 [英] Don't want to display all labels for minor ticks from ggplot2
本文介绍了不想显示来自ggplot2的所有刻度线的所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索并在Python中找到了类似的帖子,而不是R.我在此帖子中使用Richie Cotton的代码,但没有任何反应.
I searched and found a similar post in Python not R. I am using Richie Cotton's code in this post in the code, but nothing happened.
library(ggplot2)
dfr <- data.frame(x = 1:100, y = rlnorm(100))
p <- ggplot(dfr, aes(x, y)) +
geom_point() +
scale_x_log10(breaks = breaks, labels = breaks)
get_breaks <- function(x){
lo <- floor(log10(min(x, na.rm = TRUE)))
hi <- ceiling(log10(max(x, na.rm = TRUE)))
as.vector(10 ^ (lo:hi) %o% 1:9)
}
breaks <- get_breaks(dfr$x)
log10_breaks <- log10(breaks)
p + labs(axis.ticks = element_line(
size = ifelse(log10_breaks == floor(log10_breaks), 2, 1)
))
推荐答案
您可以这样做.
ggplot(dfr, aes(x, y)) +
geom_point() +
scale_x_log10(breaks = breaks, labels = c(breaks[1:3], rep("", 24)))
收益率:
这篇关于不想显示来自ggplot2的所有刻度线的所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文