Drop x-axis levels without data in facet plot and change the width of the bars

As can be seen from the data below, for some variables of the "elements" of faceted variables, some levels of the variable "axis" of the x axis are missing. For example, there is no "type = A" for "items = 32".

I want to get rid of the empty space along the x axis corresponding to non-existent "types" (for example, type A for 32 elements).

Some data ("temp"):

 type   items     value
    A      16       6.3
    B      16       8.3
    C      16       7.9
    B      32       7.7
    C      32       8.3
    C      64       7.9

Code for building:

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

enter image description here

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

Edit:

In accordance with the decision of Goran, the installation scales = "free_x"does what I want. However, the width of the bars becomes very large under the position numbers 32 and 64. Please help me make the width even for all bars.

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

enter image description here

+5
source
1

joran Etienne Low-Décarie, . , joran Etienne Low-Décarie.

, :" , . , 0 ( ).

# 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

+5

All Articles