ggplot2
使用基础函数 pretty
(通过 scales::pretty_breaks
间接使用)来处理非转换轴。您可以善加利用:
df <- data.frame(y = c(1,2,3), x=c(1,2,3))
ggplot(df, aes(x, y)) +
geom_line() +
scale_x_continuous(breaks = c(pretty(df$x), 1.5), labels = c(pretty(df$x), 'hi'))
在1.5版本中,它当然会重叠(您写的是“additional”,而不是“replace”,所以我不确定您想要什么)。如果您不想要这样,您需要做类似以下的操作:
pretty_br <- pretty(df$x)[abs(pretty(df$x) - 1.5) > 0.25]
ggplot(df, aes(x, y)) +
geom_line() +
scale_x_continuous(breaks = c(pretty_br, 1.5), labels = c(pretty_br, 'hi'))