Leo Omran
Leo Omran

Reputation: 23

How can I position the histograms vertically

I am new to R and my professor asked me to position the histograms vertically. I am required to use only ggplot2. Here is my code:

(ggplot(data=shippingData, aes(Days)) + 
  geom_histogram(binwidth=1,col="gray", 
                 fill="steelblue", 
                 alpha = 1)  +
  labs(title="Delivery Times(in Days) by Center") +
  labs(x="Days)", y="Count") + facet_grid(facets=. ~ Center))

Output is positioned as horizontally like this :

My output

But it is supposed to look like this:

Wanted output

Upvotes: 2

Views: 579

Answers (2)

Ben Bolker
Ben Bolker

Reputation: 226637

Try facet_grid(facets=Center ~ .) or facet_wrap(~Center, ncol=1)

Upvotes: 2

hunter
hunter

Reputation: 160

You could also try facet_grid(rows = vars(Center).

If you want to use facet_wrap to get the labels on top, try this:

facet_wrap(~Center, nrow = 3).

Upvotes: 2

Related Questions