0

I'm making a multi-plot figure for publishing with ggplot2 using facet_wrap(). The x-axis labels only show on the bottom plots, which is perfectly fine, but there's not even an axis on the top plots. This reduces the readability imo and I'm pretty sure most publishers will not like this.

How do I get an x-axis there without labels?

My figure (with some quick example code): enter image description here

The code:

library(ggplot2)

# theme settings (just to get the exact same example plot)
theme_set(theme_bw()) 
font <- "serif"
theme_update(axis.line = element_line(colour = "black"),
             axis.title.x = element_text(size = 16, colour = 'black', family = font),
             axis.title.y = element_text(size = 16, colour = 'black', family = font, angle = 90),
             axis.text.x = element_text(size = 14, colour = 'black', family = font),
             axis.text.y = element_text(size = 14, colour = 'black', family = font),
             legend.text = element_text(size = 12, colour = 'black', family = font),
             legend.title = element_blank(),
             legend.position = c(0.95,0.9),
             legend.box = "vertical",
             strip.text.x = element_text(size = 14, colour = 'black', family = font),
             strip.text.y = element_text(size = 14, colour = 'black', family = font, angle = -90),
             strip.text = element_text(hjust = 1),
             strip.background = element_blank(),
             panel.background = element_rect(fill = "white"),
             panel.grid.minor = element_blank(),
             panel.grid.major = element_blank(),
             panel.border = element_blank(),
             plot.title = element_text(size = 15, face = "bold", family = font, vjust = 1, hjust = 0.5))

# example data
count <- c(10,5,6,9,2,4,8,3,1,12,5,3)
stage <- rep(c("AD","NY"),6)
treat <- rep(c("A","B","C","D"),3)
days <- c(0,7,14,21,28,35,42,49,56,63,70,77)
df1 <- data.frame(count,stage,treat,days)

# example plot
ggplot(data=df1, aes(days,count,fill=stage)) +
  facet_wrap(~treat) +
  geom_col(position = "dodge",color="black") +
  #expand = put 0 on intersection
  scale_y_continuous(expand = c(0,0), limits = c(0,15)) + 
  scale_x_continuous(expand = c(0,0), limits = c(0,80)) +
  ylab("# per plant") +
  xlab("Days after release")
Roland
  • 127,288
  • 10
  • 191
  • 288
Tingolfin
  • 825
  • 8
  • 28
  • 2
    https://rdrr.io/cran/lemon/man/facet_rep.html – Roland Aug 27 '18 at 08:02
  • @beetroot that's not what I want, I do not want ticks or labels. Only the axis-line. – Tingolfin Aug 27 '18 at 08:24
  • @Roland is it possible this is depricated? the argument "repeat.tick.labels" doesn't work with facet_wrap() and the function facet_rep_wrap() as mentioned on that link gives an error that it does not exist – Tingolfin Aug 27 '18 at 08:27
  • 1
    The lemon package is still on CRAN and contains the function `facet_rep_wrap`. – Roland Aug 27 '18 at 08:29
  • Sorry, didn't notice it was in another package than ggplot... my mistake! Anyway the 2nd duplicate question beetroot posted gave me the answer indeed. Adding this to the ggplot code gives axis-line without ticks or labels: `annotate("segment", x=-Inf, xend=Inf, y=-Inf, yend=-Inf) + annotate("segment", x=-Inf, xend=-Inf, y=-Inf, yend=Inf)` – Tingolfin Aug 27 '18 at 08:35

0 Answers0