0

I keep getting the error:

Error in geom_bar(subset = .(gender == "Male"), aes(y = TotalNo)) > :Error occurred in the 3rd layer. Caused by error in setup_params(): ! stat_count() must only have an x or y aesthetic.`

My Code:

ggplot(data = ElasmobranchSex, aes(x = TotalNo, fill = Sex, y=Quarter)) + 
geom_bar(stat= 'identity')+ 
   geom_bar(subset=.(gender=="Female")) + 
  geom_bar(subset=.(gender=="Male"),aes(y=quarter))+
  geom_bar(stat='identity')+
  scale_x_discrete(labels= quarter)
  xlab("Year") +
  coord_flip() +
  theme(text = element_text(size=16)) +
  scale_y_continuous(breaks=seq(-500,500,10),labels=abs(seq(-500,500,10))) + 
  scale_fill_brewer(palette="Dark2") +
  facet_wrap(~Classification)`

Quarter is a column in my data quarter= is the labels 1-4 sanctioned

I am trying to created 3 facet charts next to each other (Shark,Skate,Ray) with male and female on each side of each chart. Attached is the kind of graph I am trying to produce.

enter image description here

Phil
  • 7,287
  • 3
  • 36
  • 66
  • Does this answer your question? [R ggplot2: stat\_count() must not be used with a y aesthetic error in Bar graph](https://stackoverflow.com/questions/39679057/r-ggplot2-stat-count-must-not-be-used-with-a-y-aesthetic-error-in-bar-graph) – Captain Hat Jun 14 '23 at 14:18
  • Hi, welcome to the stack! I've flagged this as a dupe. You're getting this error because you haven't called `stat = "identity"` in your third call to `geom_bar()`: `geom_bar(subset=.(gender=="Male"),aes(y=quarter))` – Captain Hat Jun 14 '23 at 14:19
  • 1
    Could you please share some reproducible data using `dput`? – Quinten Jun 14 '23 at 14:32
  • Error: Discrete value supplied to continuous scale. This is the error that occurs now. – madison powell Jun 14 '23 at 15:34
  • Here you have a discrete x axis, and continuous y axis. You're passing `quarter` to the y-axis, but also passing it to labels on the x-axis, which is likely causing the mismatch between discrete and continuous scales. – nrennie Jun 15 '23 at 09:12

0 Answers0