r - How to create a "gap" in a barplot? -


how achieve "gap" in barplot, this:

barplot gap

i tried create empty column in contingency table, couldn't.


sample data:

groups = c("a", "b") choices = c("orange", "apple", "beer") dat <- data.frame(     group = rep(groups, c(93, 94)),     choice = factor(c(             rep(choices, c(51, 30, 12)),             rep(choices, c(47, 29, 18))         ),         levels = choices     ) ) barplot(table(dat), beside = true) 

original barplot

you can achieve with:

barplot(table(dat), beside = true,         space = c(0, 0, 1.5, 0, 3, 0)) 

the logic space values fiddly:

  • you don't need space before first bar- first value 0
  • you don't need space between first , second bars (the 2 "orange" bars)
  • you need standard amount of space before first bar of "apple"
  • you need space before first "beer" bar

result:

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -