如何将附加常量文本粘贴到 ggplot 分面标签?
例如,我现在有这样的情节:
library(ggplot2)
df <- data.frame(
x = rnorm(120, c(0, 2, 4)),
y = rnorm(120, c(1, 2, 1)),
z = letters[1:3]
)
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~z)
创建于 2024-05-05,使用reprex v2.0.2
现在假设我想Foo =
向所有方面标签添加相同的前缀 ( ) 字符串:
如果我做
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~z, labeller = \(x) paste("foo = ", x))
我得到:
如何调整我传递给labeller
show 的函数foo = [preexisting label]
?
你必须
labeller()
像这样将你的函数包装在里面: