I have a dataframe that I would like to plot in a similar way to one of the examples on the ggplot2 bar-plot page. The example is this one:
ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)
My question is that imagine in the diamonds dataset there were no Ideal cut VV21 clarity diamonds:
newdiamonds <- diamonds[diamonds$clarity != "VVS2" & diamonds$cut != 'Ideal', ]
ggplot(newdiamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)
If you draw this plot the “Ideal” position is still there even though there is no bar to be drawn. Is it possible to suppress drawing of this unused space? In this case it is not useful but in my case I have two columns of variables – ‘data’, and ‘grouping’. I would like to facet across ‘grouping’ and display by ‘data’. For groups of ‘grouping’ where a member of ‘data’ doesn’t have a value, I don’t want ggplot to draw it.
EDIT
Along the lines of the the two answers I am looking for a graph that would look like this:
ggplot(newdiamonds, aes(cut, fill=cut)) + geom_bar() + coord_flip() + facet_grid(clarity~.)
But where each group may have only one or more ‘cut’ attributes in it.

Alternatively, you can add the argument
scales='free'to yourfacet_gridcall.But I would choose the other answer, he just wrote it faster!