# Loading data
data(CPS85, package = "mosaicData")
# Count the number of females and males in each sector
plotdata <- group_by(CPS85,sector) %>%
count(sex)
# Print the data
print(plotdata)
# Construct a ggplot object according requirement above and assign it to 'plt'
plt <- ggplot(plotdata,
aes(x = sector,
y = n))+
geom_col(aes(fill=sex))+
geom_text(aes(label=n),
position = position_stack(vjust = 0.5))+
labs(x = "",
y = "Number of persons",
title = "")
# Display the stacked bar chart
plt
But I want the number in this stacked bar chart be like:
How could I change my vjust to make the number in the middle of the stacked bar