0

I'm struggling with something I'm trying to do in R.

I have two datasets with the same (categorical) columns but different values. I want to compare the count of each combination of columns (e.g. male and married, female and single etc) visually. This is easy enough to do with ggplot's geom_bar for each dataset, and I know I can put the counts for each dataset next to each other by binding them and setting position = "dodge".

My question is whether there's an easy to way to plot the difference between the two counts for each pair of variables. And whether there's a way of changing the default 'count' method in geom_count (ironic I know) to other things (like proportion or, maybe in this case, a predefined set of values for the difference).

Thanks

  • 4
    This sounds a bit like an [XY problem](https://en.wikipedia.org/wiki/XY_problem). Rather than trying to make `ggplot2` calculate the difference between the counts, perhaps performing this data manipulation should happen _prior_ to plotting. Additionally, SO users will find it difficult to help you without a [minimal and reproducible example](https://stackoverflow.com/a/5963610/5619526). – bouncyball May 30 '18 at 13:01
  • I feared it might be necessary to do the data manipulation beforehand. Thanks for your help – Joe Pemberton May 30 '18 at 13:43

0 Answers0