Filter on ggplot - CPUE histogram

Hi all,

For study, I have to calculate the CPUE (Catch Per Unit Effort). I would like to make a representation with geom_col (stacked bars) based on different attributes of one of my columns.

Let me explain, first I calculated my CPUE like this:

cpue_data <- df %>% 
  group_by(Station,Area, Type) %>% 
  summarize(Trip_CPUE = sum(Number) / mean(Time..min.)) %>% 
  group_by(Area, Station, Type) %>% 
  summarize(Median_CPUE_Fish_min = median(Trip_CPUE, na.rm=T)) 

I then wanted to do my ggplot, which works very well, I have what I wanted.
However I would like to make a histogram by "Type" because by suddenly putting a lot of data (small values) are not visible because hidden by the large scale of the graph, necessary for very large CPUE values.

cpue_data %>% 
  group_by(Area, Station, Type)  %>% 
  ggplot(aes(x = Station, y = Median_CPUE_Fish_min)) + 
  geom_col(aes(fill = Type), width = 0.7) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  scale_fill_manual(values=c("Black", "Red", "Green")) + 
  facet_grid(~factor(Area,levels = c("A","B","C","D")),scale = "free_x", space = "free_x", switch = "x")

So I tried this code with filter but it gives me this error message: ""Error: Faceting variables must have at least one value""

cpue_data %>% 
  filter(Type == 'Adult') %>% 
  group_by(Area, Station) %>% 
  ggplot(aes(x = Station, y = Median_CPUE_Fish_min)) + 
  geom_col() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  scale_fill_manual(values=c("Black", "Red", "Green")) + 
  facet_grid(~factor(Area,levels = c("A","B","C","D")),scale = "free_x", space = "free_x", switch = "x")

If anyone have an idea to how to resolve let me know !
Hersh

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.