5

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 since 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)
Community
  • 1
  • 1
Andreas
  • 6,612
  • 14
  • 59
  • 69
  • Duplicate: see also http://stackoverflow.com/questions/3472980/ggplot-how-to-change-facet-labels – naught101 Oct 23 '12 at 02:18
  • 1
    @naught101 Just to be clear - this question was asked in may, while the other question was asked in august. – Andreas Oct 25 '12 at 06:52

1 Answers1

11

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)
Benjamin Cheah
  • 1,401
  • 17
  • 23
kohske
  • 65,572
  • 8
  • 165
  • 155
  • Thank you so much! - I tried labeller - but was thrown of... This was very helpfull. My final solution needed paste though: f<-function(x,y){if(x=="spped"){c(paste(y[-length(y)]), "Total")} else y} Thanks again!!! – Andreas May 24 '10 at 07:01