I am trying to change the width of the bars in the chart in the code below, using the width
. However, I have not been successful. Can you help me?
The data used:
Analises | Total |
---|---|
Correlation | 3 |
Mathematical models | 4 |
Posteriori test | 6 |
Multivariate hypothesis testing | 17 |
Univariate hypothesis testing | 29 |
The code used:
grafico5=ggplot(analises, aes(x= reorder(Analises, Total), y= Total))
geom_bar(stat = "identity", width = 0.5) scale_y_continuous(limits = c(0,30), breaks = seq(0,30,5))
coord_flip() xlab("Statistical analysis") ylab("Number of articles")
theme(axis.title.x = element_text(colour = 'black', size = 16, family= "sans", face= "bold"),
axis.title.y = element_text(colour = 'black', size = 16, family= "sans", face= "bold"))
geom_col(position = position_dodge())
theme(axis.text.x = element_text(colour = 'black', size = 14, family= "sans"),
axis.text.y = element_text(colour = 'black', size = 14, family= "sans"),
panel.background = element_rect(fill = "white"), axis.line = element_line(size = 0.5, colour = "black"))
geom_col(fill = gray(.3))
CodePudding user response:
You are successfully changing the width of the geom_bar()
, but then on top you are plotting the same thing at the default width with geom_col()
, twice. If we delete your geom_col()
lines it works:
ggplot(analises, aes(x= reorder(Analises, Total), y= Total))
geom_bar(stat = "identity", width = 0.5)
scale_y_continuous(limits = c(0,30),breaks = seq(0,30,5))
coord_flip()
xlab("Statistical analysis") ylab("Number of articles")
ggplot(analises, aes(x= reorder(Analises, Total), y= Total))
geom_bar(stat = "identity", width = 0.25)
scale_y_continuous(limits = c(0,30),breaks = seq(0,30,5))
coord_flip()
xlab("Statistical analysis") ylab("Number of articles")