Sehj Kashyap
Sehj Kashyap

Reputation: 57

How do I Create a Faceted Bar Graph with Different Discrete X Axis in R ggplot

I have a bar graph which looks like the following:

Graph that I would like to facet

Problem: If I facet it by the same variable as the color, the x-axis has space for plotting all the bars even though I don't need them.

Faceted plot with extra spaces

My Solution: I used multiplot function from the Rmisc to separately make bar graphs for each partner but then a lot of individual customization is needed to make the graphs go cohesively together.

Make-shift graph using Rmisc::multiplot function

Question: Is there another way that I can use to get closer to plot 2 without the extra spaces for the variables that don't apply.

I'm using ggplot to plot.

Upvotes: 0

Views: 1548

Answers (1)

Puddlebunk
Puddlebunk

Reputation: 493

use:

+ facet_wrap(~variable_to_facet_by, 
             scales = 'free')

as part of your ggplot code and that should get you what you want.

Upvotes: 3

Related Questions