如何使用facet和margin = TRUE更改ggplot中的strip.text标签

And*_*eas 5 label locale r facet ggplot2

我看过这里但仍然无法弄明白.如何使用分面更改ggplot中的strip.text.x标签?具体来说,我使用带边距的facet_grid.保证金的strip.text标签是"(全部)" - 但由于我在非英语国家,我宁愿用我的母语写"Total"或类似的东西.

opts(stip.text.x=c(levels(facetvariabel,"Total")) does not work.
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

示例(不是真正的最佳数据集 - 但我想它会起作用)

ggplot(cars, aes(x=dist))+geom_bar()+facet_grid(.~speed, margin=T)
Run Code Online (Sandbox Code Playgroud)

koh*_*ske 10

您可以通过提供贴标机功能来自定义构面标签:

f <- function(x, y) {
  if (x == "speed")
    c(y[-length(y)], "Total")
  else
    y
}

ggplot(cars, aes(x = dist)) +
  geom_bar() +
  facet_grid(. ~ speed, margin = TRUE, labeller = f)
Run Code Online (Sandbox Code Playgroud)