dataset1$question1 <- factor(dataset1$question1, levels = c("Disagree","Agree","Neutral"))
ggplot(dataset1 %>%
group_by(jobgroup) %>%
count(question1) %>% # Group by jobgroup, then count number in each question1
mutate(jobgroupCnt=paste(jobgroup," , n= ",sum(n), sep=""), #this variable gives the total count within each jobgroup
pct=n/sum(n)), # Calculate percent within each jobgroup
aes(jobgroupCnt, pct, fill=question1,order=question1)) +
geom_bar(stat="identity") +
geom_text(aes(label=paste0(sprintf("%1.1f", pct*100),"%")),
position=position_stack(vjust=0.5),size=3)+
labs(title = "", y = "Percent", x = "Job Group")+ #add the title yourself
theme(legend.title = element_blank(),
panel.grid.major = element_blank(),
axis.text.x=element_text(hjust=0.5,vjust=0.5), #adjusted both vertically and horizontally on the center
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"))