-1

I need to exclude the empty observations i.e. to be able to see only the bars and not the blank observations Now it is somehow wrong...

   ggplot( frame, aes( y = sil_width, x = observation) )+
      coord_flip()+
      geom_bar(stat="identity") +
      facet_grid( cluster~., labeller = label_both) 


> frame
   cluster neighbor sil_width observation
10       1        2 0.9044976          10
6        1        2 0.9040205           6
2        1        2 0.8969660           2
4        1        2 0.8966644           4
1        1        2 0.8959830           1
5        1        2 0.8866528           5
9        1        2 0.8548683           9
7        1        2 0.8408474           7
3        1        2 0.8389057           3
8        1        2 0.7521333           8
12       2        1 0.9252061          12
15       2        1 0.9250464          15
17       2        1 0.9189154          17
20       2        1 0.9171968          20
13       2        1 0.9144334          13
24       2        1 0.9106160          24
19       2        1 0.9072514          19
18       2        1 0.8991627          18
14       2        1 0.8931934          14
23       2        1 0.8919554          23
16       2        1 0.8877312          16
22       2        1 0.8794240          22
11       2        1 0.8777455          11
21       2        1 0.8660889          21
25       2        1 0.7620662          25

ggplot

Marcin
  • 7,834
  • 8
  • 52
  • 99
  • Sorry :) it should be aesthethic http://docs.ggplot2.org/0.9.3/aes.html – Marcin Nov 19 '14 at 18:06
  • I don't see anything doubled here. Whatever is in cluster 1 is on the cluster 1 facet. Unless you need to exclude the empty observations i.e. to be able to see only the bars and not the blank observations? – LyzandeR Nov 19 '14 at 18:11
  • And, as Henrik comments [here](http://stackoverflow.com/q/18901140/903061), there are posts [here](https://groups.google.com/forum/#!searchin/ggplot2/facet_grid$20free$20coord_flip%7Csort:relevance) suggesting that the solution (`scales = "free"`) doesn't play well with `coord_flip`, so you may need to switch your `x` and `y` and not use `coord_flip`. – Gregor Thomas Nov 19 '14 at 18:37

1 Answers1

2

The only way to do this is using facet_wrap and not facet_grid like this:

a <- ggplot( frame, aes( y = sil_width, x = observation) ) 
a + facet_wrap( ~cluster ,  scales='free') + geom_bar(stat='identity', shape=1) 

enter image description here

Unfortunately, coord_flip won't work with facet_wrap so this is the best you can have.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • I think there is a problem with your x axis. Like those characters were treated as integers but they are really characters. – Marcin Nov 19 '14 at 18:44