How to pass a count of observations to the facet label?
问题 I would like to add a count of observations in each facet to the "title" of each facet. For instance, I have this: library(tidyverse) mtcars %>% ggplot(aes(x = cyl)) + geom_bar()+ facet_wrap(~carb) and I would like to add the frequencies from the below function to each label table(mtcars$carb) 1 2 3 4 6 8 7 10 3 10 1 1 Thus the label for 1st row 1st column should be 1; n=7 the 1st row 2nd column 2; n=10 etc... 回答1: A solution using tidyverse . We can create an updated column to show the count