How to put spaces between bars in ggplot2 barplot
2
1
Entering edit mode
4 months ago

Hi, I want to put spaces between each pair of bars in my barplot.

This is my code

ggplot(Germ, aes(x = G, y = T, 
             color = c('WT', 'at5g01950')[2 - (as.numeric(G) %% 2)])) +
geom_bar(position="dodge", stat="identity") +
geom_boxplot(width = 0.5, color = "black", alpha = 0.2, 
             position = position_dodge(0.9)) + 
theme_minimal() + 
theme(plot.background = element_rect(fill = "white") ,
      panel.grid.minor = element_blank()) +
labs(color = '')

This is my barplot

enter image description here

It would be nice to add the space of a bar, or even less, bewteen, for example, bars pairs 1,2 and 3,4, and so on.

Thank you

r ggplot2 • 675 views
ADD COMMENT
0
Entering edit mode

Why is it that you thanked me for the post that told you to search online, then deleted it and asked a similar question? You see how the other users here has also asked you to search online, right? Please stop this behavior.

ADD REPLY
1
Entering edit mode
4 months ago
bhumm ▴ 140

This is a general R question and not related to bioinformatics, thus is likely better for stackoverflow. After a quick google search you likely want to tinker with the width parameter within the geom_bar layer. See this SO post: https://stackoverflow.com/questions/6085238/adding-space-between-bars-in-ggplot2

ADD COMMENT
0
Entering edit mode
4 months ago

this isn't really a bioinformatics question, but you alter the distances using both position=position_dodge(width=0.5) and width=0.5 in your boxplot and bar geometries.

Also, to properly dodge and color the bars create a column with the group and then just pass the column name to fill= in the aesthetics function of ggplot.

ADD COMMENT

Login before adding your answer.

Traffic: 2266 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6