r - Barchart faceting by class in ggplot2, while preserving the label-structure of the y-axis -


i utilizing ggplot2 package in r plot functional categories count. seen in plot below, categories have been ordered protein count , class fall into.

enter image description here

here portion of dataset working with:

go_category                              protein_count  class aromatic amino acid family metabolic process        24  amino acid metabolism glutamine family amino acid metabolic process       14  amino acid metabolism aspartate family amino acid metabolic process       10  amino acid metabolism glutamine family amino acid biosynthetic process    9   amino acid metabolism branched-chain amino acid metabolic process         8   amino acid metabolism peptidyl-lysine modification hypusine            4   amino acid metabolism ornithine metabolic process                         3   amino acid metabolism single-organism carbohydrate metabolic process      125 carbohydrate metabolism carbohydrate biosynthetic process                   55  carbohydrate metabolism pentose metabolic process                           7   carbohydrate metabolism mannose metabolic process                           3   carbohydrate metabolism organelle organization                              101 cellular components ribonucleoprotein complex biogenesis                41  cellular components plastid organization                                35  cellular components 

here code using in r:

nameorder <- df$go_category[order(df$class, df$protein_count)] df$go_category <- factor(df$go_category, levels=nameorder) ggplot(data=df, aes(x=go_category, y=protein_count, fill=go_category)) +    geom_bar(color="black", stat="identity", width=0.5, position=position_dodge(.5)) +    coord_flip() +    guides(fill=false) +    ylab("protein association count") + xlab("gene ontology category") +   theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank(), axis.text.y=element_text(colour="#999999")) +    theme(panel.background = element_blank()) +   theme(text = element_text(size = 10)) +   geom_text(aes(label = protein_count), size = 3, hjust = -0.5) 

what facet groups class identifier, maintaining structure of y-axis. attempts @ have produced rather ugly plots seem repeat labels on y-axis each facet.

enter image description here

facet_wrap has argument scales can use. scales='free_y' (or possibly 'free_x' if did coord_flip() make plot) should trick - http://docs.ggplot2.org/0.9.3.1/facet_wrap.html

'free' in context of factor variables means values aren't observed within category aren't shown on axis.

use in conjunction space = 'free_x'/'free_y' make scale same across facets (so categories fewer or more categories aren't shrunken/enlarged.

edit: space isn't implemented facet_wrap yet, may able achieve want facet_grid


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -