I've a data.frame that looks like this:
> foo
class type (0,10] (10,20] (20,30] (30,40]
1 A <NA> 0.6 0.2 0.1 0.1
2 B <NA> 0.7 0.1 0.1 0.1
3 C 1 0.5 0.4 0.1 0.0
4 C 2 0.5 0.3 0.1 0.1
5 D 1 0.7 0.3 0.0 0.0
6 D 2 0.7 0.2 0.0 0.1
7 E 1 0.4 0.3 0.2 0.1
8 E 2 0.5 0.3 0.1 0.1
I melt by class & type and do a barplot:
ggplot(melt(foo, id=c("class", "type")), aes(x=variable, y=value, fill=class)) +
geom_bar(position="dodge") +
facet_grid(type ~.)
In fact, facet_grid()
creates 3 graphs, but what I want is, somehow, to 'ignore' that class A & B are type and display them both in the facet for type 1 and type 2, and get only 2 graphs (A and B values should be, in fact, repeated):
I try to avoid modifying manually and duplicate A and B with type 1 and 2, because I need the original data.frame as is for other graphs/tests.
(sorry the random order of the columns, I'm using different versions at home than the ones at work and don't know why it happens)