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)
Change the text of facet labels Facet labels can be modified using the option labeller , which should be a function. In the following R code, facets are labelled by combining the name of the grouping variable with group levels. The labeller function label_both is used.
By default, the size of the label is given by the Facets, here it is 9. But we can change the size. For that, we use theme() function, which is used to customize the appearance of plot. We can change size of facet labels, using strip.
facet_grid() forms a matrix of panels defined by row and column faceting variables. It is most useful when you have two discrete variables, and all combinations of the variables exist in the data. If you have only one variable with many levels, try facet_wrap() .
The facet_grid() function will produce a grid of plots for each combination of variables that you specify, even if some plots are empty. The facet_wrap() function will only produce plots for the combinations of variables that have values, which means it won't produce any empty plots.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With