I'm trying to plot some values against US states in a horizontal bar chart in GGPlot.
The code is:
g <- df %>%
select(Sample.Measurement, State.Name) %>%
group_by(State.Name) %>%
count() %>%
arrange(n) %>%
ggplot(., mapping = aes(x=reorder(State.Name, n), y =n))+
geom_bar(stat = "identity", width=.8, position = position_dodge(width = .25))+
labs(
title = "",
y= "Frequency"
)+
coord_flip()
g+theme(axis.text=element_text(size=20),
axis.title=element_text(size=30,face="bold"))
The theming element was in a bid to change the text size.
What I really want to do is extend the depth of the chart so that the individual states have more space. How do I do that?
To Increase or Decrease width of Bars of BarPlot, we simply assign one more width parameter to geom_bar() function.
To make the bars narrower or wider, set the width of each bar with the width argument. Larger values make the bars wider, and smaller values make the bars narrower. To add space between bars, specify the space argument. The default value is 0.2.
Spacing and widthsSet the width of geom_bar() to a small value to obtain narrower bars with more space between them. By default, the width of bars is 0.9 (90% of the resolution of the data). You can set this argument to a lower value to get bars that are narrower with more space between them.
It's very easy to create a horizontal bar chart. You just need to add the code coord_flip() after your bar chart code.
Edit the chunk options, namely fig.height
and fig.width
.
e.g.
```{r fig.height = 10, fig.width = 5}
#your plot code
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With