0

I am doing my first assignment with R and having a few problems trying to create a stacked bar plot. I have managed to create a bar plot of the top 20 highest paying occupations -- but I want to have this split by gender.

My code so far is:

#average total household income of each occupation
pay <- tapply(exp$INC, exp$OCC, mean)
#find top 20
toppay <- sort(pay, decreasing = TRUE)[1:20]
barplot(toppay,
las=1,
cex.names=0.6,
main = "Top 20 Highest Paying Occupations",
xlab = "Total Household Income",
col = coul,
horiz = TRUE)

How do I go about splitting this by gender? My data set has a column for the gender called SEX. Thank you in advance.

  • 1
    Please provide a small reproducible example – akrun Nov 30 '21 at 18:23
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Make sure you search carefully for existing questions because there are already a lot of questions about stacked bar plots and I'm not quite sure how this question is different and without a reproducible example it's tough to guess. – MrFlick Nov 30 '21 at 18:36
  • Did you look at the ggplot() documentation here: https://ggplot2.tidyverse.org/reference/geom_bar.html ? You can see how 'drv' was used as the stacking variable. – Ben Nov 30 '21 at 19:12

0 Answers0