'How do I find number of yes/no's within each bin of income
I am new to R and have to use it for a course at uni. My question is, I am aiming to make a bar chart like the one pictured. I want bins of income at the bottom, with two bars for each bin representing the number of "Yes" and number of "No". I'll provide pictures of what I have done so far (with the desired result bottom right), but have been stuck for the past couple hours at this point. (so, for example, how do I find number of yes's within the first bin, which is between 1000 and 5800) (and then if possible how would I recreate this bar plot with my figures). Thanks heaps everyone!
1st 5 Rows of dataset directly relating to question MonthlyIncome Attrition 1 1081 Yes 2 1232 No 3 1261 Yes 4 1420 Yes 5 1483 No
Solution 1:[1]
It's possible I've misunderstood what you're hoping to do, but maybe grouping by your Attrition value rather than subsetting it? You'd want to do a count of the number of values for each (I'd use group_by from tidyverse for that).
Alternatively, if there's a variable by which you could summarise the number of observations for each, you could use summarise(sum(var)) and then use that as your y value.
Then you can build your plot using something like:
ggplot(aes(fill = Attrition, x = MonthlyIncome, y = Count)) +
geom_bar(stat="identity")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | benson23 |
