The advance of my code is (MWE) :
# https://www.kaggle.com/kaggle/kaggle-survey-2017/data
#### Analisis primario del dataset ####
response <- read.csv(file = "multipleChoiceResponses.csv",na.strings = "")
# seleccionamos solo algunas variables :
Variables <- c("GenderSelect","Country","Age","CurrentJobTitleSelect","MLToolNextYearSelect","LanguageRecommendationSelect","FormalEducation",
"FirstTrainingSelect","EmployerIndustry")
# Mantenemos en memoria solo las variables seleecionadas :
response <- response[,Variables]
# Por un tema de cantidades solo nos quedamos con M y F
Response <- response[response$GenderSelect == "Male" | response$GenderSelect == "Female",]
# agrego una columna para los continenetes (continent) a donde pertenecen los paises (Country)
library(countrycode)
Response$continent <- countrycode(sourcevar = Response[, "Country"],
origin = "country.name",
destination = "continent")
# Convertimos a factor esta nueva variable
Response$continent <- as.factor(Response$continent)
# Eliminamos las filas con elementos NA
Response <- Response[complete.cases(Response), ]
# Enumeramos todas las filas de manera adecuada
rownames(Response) <- 1:nrow(Response)
Response <- droplevels(Response)
bp_Continent <- barplot(table(Response$continent),
main = "Distribucion de DS por continentes",
ylim = c(0,3500)
)
# Add GenderSelect proportion by continent in label argument ("BLABLABLA")
text(x = bp_Continent, y = table(Response$continent), label = "BLABLABLA", pos = 3, cex = 0.8, col = "red")
Basically, the script loads the data, chooses some of the variables, creates a new variable (continent), to finally clean the data. The next thing to do is create a barplot, placing the proportion of men and women on top of the bars
What I am looking to do is change the "BLABLABLA" to the proportion between men and women (GenderSelect variable) by continent.
My question is not at all similar to : How to display the frequency at the top of each factor in a barplot in R
Because what interests me is the calculation of the proportion and the impression above the bars.