SHARE
TWEET

blank ggplot facet labels take up space

cwdillon Oct 22nd, 2012 364 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library("ggplot2")
  2. rowSubscripts = sample(nrow(diamonds),1000)
  3. kdiamonds <- diamonds[rowSubscripts,]
  4. head(kdiamonds)
  5. summary(kdiamonds)
  6.  
  7. tgp <- ggplot(diamonds,
  8.               aes(x=carat,
  9.                   y=table,
  10.                   color=color,
  11.                   group=color
  12.                   )) +
  13.                   geom_point() +
  14.                   opts(axis.title.y=theme_blank(),
  15.                          strip.text.y=theme_text())  
  16. tgp
  17.  
  18. tgpf<- tgp + facet_grid(color ~ .,
  19.                         scales = "free_x",
  20.                         space = "fixed",
  21.                         margins = F,
  22.                         labeller="label_parsed") +
  23.                           geom_smooth(method = lm) +
  24.                           opts(strip.background = theme_blank()) +
  25.                           opts(strip.text.y = theme_blank()) +
  26.                           opts(axis.title.x=theme_blank())  
  27. tgpf
  28.  
  29. pdf("facetLabels.pdf", width = 4, height = 8)
  30. grid.newpage()
  31. pushViewport(viewport(layout = grid.layout(2,1)))
  32.  
  33. vplayout <- function(x,y)
  34.   viewport(layout.pos.row = x, layout.pos.col = y)
  35. print(tgpf, vp = vplayout(1,1))
  36. print(tgp, vp =vplayout(2,1))
  37. dev.off()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top