xBarGenerator code giving me an error in RStudio

Can you be more specific? what is the error message you are getting? what is your expected output?
Also, please turn this into a proper REPRoducible EXample (reprex), right now we can't reproduce your code since you are not showing what population is or from where it comes from.