r - Omit x axis levels with no data in a facetted plot and change widths of the bars -


as can see in data below, levels of x axis variable "type" missing of facetting variables "items". example, there no "type = a" "items = 32".

i want rid of empty space along x axis corresponding non-existing "types" (e.g., type 32 items case).

some data ("temp"):

 type   items     value          16       6.3     b      16       8.3     c      16       7.9     b      32       7.7     c      32       8.3     c      64       7.9 

code plotting:

library(ggplot2) ggplot(temp, aes(x = type, y = value, fill = type)) +    geom_bar(stat = "identity") +    facet_grid( . ~ items) 

enter image description here

=======================

edit:

according joran's solution, setting scales = "free_x" doing want. however, widths of bars become large under item numbers 32 , 64. please me make widths bars.

ggplot(temp, aes(x = type, y = value, fill = type)) +    geom_bar(stat = "identity") +    facet_grid( . ~ items, scales = "free_x") 

enter image description here

simply following directions given joran , etienne low-décarie close old unanswered question. please up-vote joran , etienne low-décarie.

also, please note roman luštrik's valuable comment above "i hope have reason this. white space informative, gives reader head's levels have value of 0 (which still value)."

# data temp <- structure(list(type = structure(c(1l, 2l, 3l, 2l, 3l, 3l), .label = c("a",  "b", "c"), class = "factor"), items = c(16l, 16l, 16l, 32l, 32l,  64l), value = c(6.3, 8.3, 7.9, 7.7, 8.3, 7.9)), .names = c("type",  "items", "value"), class = "data.frame", row.names = c(na, -6l ))  # plot library(ggplot2) ggplot(temp, aes(type, value, fill = type)) +    geom_bar(stat = "identity") +    facet_grid( . ~ items, scales = "free_x", space = "free")  

enter image description here


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -