0

I grouped the data frame I have using two variables (Species, Gender) and the counts of Grey Fox for males (blue) are zero. But the zero doesn't appear in the grouped data and is subsequently missing from the plot as well (attached). My current dataset is too big to share so I included a sample.

Sample Data and Code: Code:

df = data.frame(X = c(0,1,0,1), Y = c(0,1,0,0))

df %>% 
  group_by(X, Y) %>% 
  count()

enter image description here

Note: I converted both to factors but that didn't change the table/plot. Got the same results with tally and summarize functions as well. In this case, it was just one row so I used add_row function but I don't want to do that since I have another similar dataset where I'll need to add more than 5 rows.

enter image description here

animus
  • 77
  • 6
  • 1
    Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including example data in a plain text format - for example the output from `dput(df)`. – neilfws Feb 09 '22 at 00:24
  • Compare `mtcars %>% count(cyl, gear)` and `mtcars %>% count(cyl, gear) %>% tidyr::complete(cyl, gear, fill = list(n=0))`. – Jon Spring Feb 09 '22 at 00:44

0 Answers0