0

I am having the issue where when I try to facet data in ggplot to make bar graphs, not all data gets added into the correct facets...

I have a very large dataset, so it's inconvenient to share, but I will post examples of what one facet should actually look like.

So here is my code:

  ggplot(data=data,aes(x=data$practice_cat,y=data$pct_pop)) + 
  geom_bar(stat='identity') + facet_grid(type ~ size_f) + coord_flip()

And this is the plot that I get: enter image description here

However, the faceting is not true to the data. It seems like facet_grid is attributing certain rows to the incorrect facet. For example, for the facet total and > 10 NPIs, the graph should look more like this: enter image description here

How do I fix this?

crayfishcray
  • 379
  • 4
  • 15
  • 1
    Don't use `data$` insider your `aes()`, just use `aes(x=practice_cat, y=pct_pop)`. (You should never really have `$` inside there). If that doesn't make it better, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that we can use to run your code and see what's going on. – MrFlick Aug 02 '18 at 20:33
  • this worked! thank you :) – crayfishcray Aug 02 '18 at 20:33

0 Answers0