Reputation: 55
I am trying to change the bar width of my plots, my codes are here:
ggplot(df_densityWindow, aes(x = idx, y = density, color = factor(location))) +
geom_bar(stat = 'identity', fill = 'white', width = 1) +
theme_bw() +
facet_grid(marker ~ case, scales = 'free') +
theme(strip.background = element_rect(colour="black", fill="white"),
strip.text = element_text(margin = margin(10, 10, 10, 10), size = 40)) +
scale_color_manual(name = 'Regions',values = c("#F26969", "#02f527",'#F2F2C6')) +
background_grid(major = 'y', minor = "none") + # add thin horizontal lines
xlab('Index') +
ylab(expression(paste('Density/', mm^2, )))+
theme(axis.text = element_text(size = 38)) +
theme(axis.title = element_text(size = 40)) +
theme(legend.text = element_text(size = 38)) +
theme(legend.title = element_text(size = 40)) +
theme(axis.text.x=element_text(angle=90, hjust=1)) +
panel_border()
Since I changed the bar width to 1, I assume there should not be any overlapping between each bar, however, the results are: For a closer look: They are still overlapping with each other, how to solve this?
Upvotes: 2
Views: 935
Reputation: 3
try adding the following position setting to your geom_bar
call:
geom_bar(stat = 'identity', fill = 'white', width = 1, position = "dodge")
this should dodge the bars so that they aren't on top of each other. you can also use position_dodge
to set the spacing that you'd like manually.
Upvotes: 0
Reputation: 90
I believe the width argument is scaled to the resolution of the data, so I'd recommend experimenting with the values of both width (set it to a value less than 1) and binwidth.
Hope it works out.
Upvotes: 1