Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase size of ggplot - squeezed horizontal bar chart

Tags:

r

ggplot2

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?

GGplot chart

like image 540
elksie5000 Avatar asked Jan 11 '18 19:01

elksie5000


People also ask

How do I change the size of a bar in ggplot2?

To Increase or Decrease width of Bars of BarPlot, we simply assign one more width parameter to geom_bar() function.

How do you make a bar graph bigger in R?

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.

How do I increase space between bars in ggplot2?

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.

How do you plot a horizontal bar graph in ggplot2?

It's very easy to create a horizontal bar chart. You just need to add the code coord_flip() after your bar chart code.


1 Answers

Edit the chunk options, namely fig.height and fig.width.

e.g.

```{r fig.height = 10, fig.width = 5}
#your plot code
```
like image 80
Roman Luštrik Avatar answered Oct 25 '22 04:10

Roman Luštrik