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

后端 未结 1 2017
执念已碎
执念已碎 2020-12-15 01:45

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 st

相关标签:
1条回答
  • 2020-12-15 02:26

    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 讨论(0)
提交回复
热议问题