My dataset looks like this:
| V1 | V2 | V3 | V4 |
|---|---|---|---|
| 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
I want to plot a count of the occurrences of 1s per variable, but on one single bar chart (4 bars). I can plot this for each individual variable using ggplot:
ggplot(df,aes(x = v1)) +
geom_bar(stat = 'count')
, but to plot them all on one graph I seem to need to turn my dataframe sideways, but then I can't figure out how to calculate the count of 1s.
Any help would be much appreciated!
