Advertisement
cwdillon

blank ggplot facet labels take up space

Oct 22nd, 2012
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.17 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement