Hello all,
How do I re-arrange the bars in my graph so that the x-axis variables stay grouped together and stay in the same exact order they are currently in, but the bar's height's are correct?
For some reason my code (below) is scrambling up the bar height....the columns with lower text labels have higher values. Also, the y-axis is off, since half of the bars have text labels above the max value. I'm not sure what is going on.
By the way the variables and axis names in this graph and data set are all renamed to be nonsensical. This is data from a study that is currently in collection and I would rather not post results at this time.
newdata%>%
ggplot(aes(x=Movie,
y=Loved_it,
fill=Age))+ #fill indicates a grouping variable to color/sort by. Can also use "group="
geom_col(stat = "identity",
position = position_dodge2(preserve = "single"), #_dodge puts columns next to one another; ()specifies distance between columns
colour="black")+ #outline columns in black
geom_text(aes(label = scales::comma(n)), #Label each column with text; include commas in labels if number hits 1,000+
size = 2.5,
position = position_dodge(width = 0.9), #center the labels over the columns
vjust = 1)+ #vertically adjust the position of the labels x units from the column top
theme_light()+
scale_y_continuous(labels = scales::comma)+
labs(x = "Movie",
y = "Count",
title = "SW Prequal appreciation by age group")+
theme(plot.title = element_text(hjust = 0.5))+ # this theme command centers the title
theme(text = element_text(family = "Century Gothic",size = 10), #family= changes all fonts in the graph to the same font
axis.title = element_text(face = "bold"),
axis.text = element_text(face = "italic"),
plot.title = element_text(face = "bold",size = 12))+
scale_fill_manual(values = c("gray75","red"))+ #customize the fill colors used by the "fill=" call above
theme(panel.grid = element_blank()) #remove gridlines