[R] Universal axis is overwritten in ggplot panel plot using grid.arrange

Joe Ceradini
Wed, 26 Aug 2015 23:35:41 -0000

R-helpers,

I am trying to make a panel of ggplots with universal Y and X axes. There
are many examples that show how to do this with grid.arrange. However, my x
axis label looks like it is (maybe) overwritten by the margin of the lower
left plot and I cannot figure out how to fix it. I realize this is not a
reproducible example, but I'm hoping the problem is obvious to someone more
experienced. I attached a pdf of the plot (which, if I understood the
posting guide correctly, will not be stripped off before posting).

Thanks!

*Code for one plot (lower left) and grid.arrange:*

E <- ggplot(data, aes(x = data_x)) +
  geom_line(aes(y = estimate), color = "black", linetype =
"solid", size .6) +
  geom_line(aes(y = lcl), color = "black", linetype =
"dashed", size = .6) +
  geom_line(aes(y = ucl), color = "black", linetype =
"dashed", size = .6) +
  scale_y_continuous(limits = c(0.0, 1), breaks = seq(0.0, 1, .25)) +
  scale_x_continuous(limits = c(0, 80), breaks = seq(0, 80, 20)) +
  ggtitle("E)") +
  theme_bw() +
  theme(text = element_text(family = "Times"),
        plot.title = element_text(hjust = 0.2, vjust = -1, face =
"bold",
size = 10),
        axis.text.x = element_text(size = 14),
        axis.text.y = element_text(size = 14),
        axis.title.x = element_blank(), # element_text(size = 16,
vjust=-0.5, hjust = 0)
        axis.title.y = element_blank(),
        plot.margin = unit(c(-1, 0.05, 2, .6), "lines"), # top, right,
bottom, left
        panel.border = element_blank(), # removes plot border
        panel.grid.major = element_blank(), # removes major gridlines
        panel.grid.minor = element_blank(), # removes minor gridlines
        axis.line = element_line(size=.25), # add x and y axis lines and
control width
        axis.ticks = element_line(size=.25), # tick width
        axis.ticks.length = unit(.1, "cm"))

grid.arrange(A, B, C, D, E, ncol=2,
            left = textGrob("U  n  i  v  e  r  s  a  l   Y   A  x  i
s",
                            rot = 90, vjust = .6, hjust = .45,
                            gp = gpar(fontsize = 20, fontfamily =
"Times")),
            bottom = textGrob("U  n  i  v  e  r  s  a  l   X   A  x  i
s",
                              hjust = 1, vjust=5,
                      gp = gpar(fontsize = 20, fontfamily = "Times")))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: axis_obscured.pdf
Type: application/pdf
Size: 8348 bytes
Desc: not available
URL:
<https://stat.ethz.ch/pipermail/r-help/attachments/20150826/d764992c/attachment.pdf>