开发者

how to change strip.text labels in ggplot with facet and margin=TRUE

I have looked here but still can't figure it out. How do I change the strip.text.x labels in a ggplot with faceting? Specifically I am using facet_grid with margins. The strip.text label for the margin is "(all)" - but si开发者_StackOverflownce I am in a non-english speaking country I would rather write "Total" or something similar in my native tongue.

opts(stip.text.x=c(levels(facetvariabel,"Total")) does not work.

Any ideas?

Example (not really the best dataset for this - but I guess it will work)

ggplot(cars, aes(x=dist))+geom_bar()+facet_grid(.~speed, margin=T)


You can customize the facet labels by giving labeller function:

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜