How to change the length of the x/y-axsis - ggplot

Hey together, I have a question regarded to ggplot. I have these graphs and I want to read all the percentages of course, but if I change the contionous_scale_y with expand(c(0,0)) to another value e.g., expand (c(0,0.1)) then I can see the percentages but then the bars are of course not directly on the y-axis anymore. My question would be - how can I see all the percentages of my graph (see problem in screenshot), but the bars should still be sticked on the y-axsis - this is my Current code:

ggplot(data, aes(x = HHincome)) +
geom_bar(aes(y = (..count..)/sum(..count..)), fill ="blue") +
geom_text(aes(y = ((..count..)/sum(..count..)), label = scales::percent(round(..count..)/sum(..count..),0.01)), stat = "count", hjust = -0.2, size = 3, family = "Times New Roman", colour = "black") +
scale_y_continuous(labels = percent, expand = c(0,0)) +
labs(title = "Distribution of Variable Household Income") +
coord_flip() +
theme(panel.background = element_blank(), text = element_text(family = "Times New Roman", size = 10),axis.ticks.x = element_blank(), axis.text.x = element_blank(), axis.title.x = element_blank(), plot.title = element_text(size = 12, hjust = 0.5, vjust = 3), axis.title.y = element_blank(), axis.line.y = element_line(size = 0.5, colour = "black"))

Help is highly appreciated! Thank you so much!

You can set the max limit to be a value slightly larger than the largest percentage in your visual (assuming 0.1 works).

scale_y_continuous(labels = percent, expand = c(0,0), limits = c(0, 0.1)) +

The correct way of using expand in this situation is this one

scale_y_continuous(labels = percent,
                   expand = expansion(mult = c(0, 0.1))) +
coord_cartesian(clip = "off")

Setting "clip = off" also helps

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.