我的问题与这个问题类似,但在一个重要方面略有不同。我想使用{scales}
包中创建的不同标签函数来为刻度标记标签(而不是轴标签)进行标注。以下是可再现的示例:
library(ggplot2)
library(scales)
mill <- number_format(scale = 1/1000000, suffix = " M")
thou <- number_format(scale = 1/1000, suffix = " k")
df <- data.frame(cond = rep(c("A", "B", "C"), each = 5),
x_unit = rep(1:5, 3),
y_unit = round(c(rnorm(5, 5e6, 10000),
rnorm(5, 5e6, 10000),
rnorm(5, 5000, 1000))))
ggplot(df, aes(x = x_unit, y = y_unit)) +
geom_line() +
scale_y_continuous(labels = mill) +
facet_wrap(~ cond, scales = "free_y")
你可能已经看出我想说什么了:对于 C 维度,我想使用标签函数 thou
而不是 mill
。该怎么做呢?我相信我在上面链接的问题中提到的使用 facet_wrap()
中的 labeller
参数的解决方案在这里不适用,对吗?