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.