0

I have the following dataset:

data <- data.frame(name = c(rep("ventilation",4), rep("feed",4)),
                   tech = c("air","air","fan","fan","nipple","nipple","mfold","mfold"),
                   success = rep(c(0,1),4),
                   freq = c(.669,.331,.596,.404,.62,.38,.654,.346)) %>%
  mutate(success = factor(success))

data
         name   tech success  freq
1 ventilation    air       0 0.669
2 ventilation    air       1 0.331
3 ventilation    fan       0 0.596
4 ventilation    fan       1 0.404
5        feed nipple       0 0.620
6        feed nipple       1 0.380
7        feed  mfold       0 0.654
8        feed  mfold       1 0.346

And I want to create a bar plot using geom_plot, but grouping by name, tech and success. So I tried to use facet_wrap in order to facet by name. This is my first attempt:

data %>%
  ggplot(aes(x = tech, y = freq, fill = success)) +
  geom_col() +
  facet_wrap(~name)

And this is the result:

enter image description here

But then I see that classes "air" and "fan" are in the facet "feed", and classes "mfold" and "nipple" are in the facet "ventilation". Is there a way I only see the corresponding classes per each facet? (for example in facet "feed" I only want to appear "mfold" and "nipple"). Any help will be greatly appreciated.

Alexis
  • 2,104
  • 2
  • 19
  • 40

0 Answers0