0

I have a facet_wrap that looks good; however, I want to only have the external lines with actual numerical data and the internal graph lines with tick marks. I am not sure if there is a way top do thisDesired plotthe first image is the desired plot edited in slides and the second is an R plot that needs to be changed. plot with removed inner lables

My current code is

ggline(ACE2data2, x = "Time", y = "Fluorescence") +
  labs(x = "Time (min)", y = "RFU Ex/Em 320/420nm") +
  theme(axis.title.x = element_text(size = 22)) +
  theme(axis.title.y = element_text(size = 22)) +
  facet_wrap2(~ Dilution,
              nrow = 5,
              ncol = 4,
              axes = "all") +
  force_panelsizes(rows = unit(4, "cm"), cols = unit(4, "cm")) +
  coord_cartesian(ylim = c(0, 10000)) +
  theme(strip.text.x = element_blank(), strip.background = element_blank())

Any help is sincerely appreciated!! A big thanks in advance :)

stefan
  • 90,330
  • 6
  • 25
  • 51
Regan
  • 21
  • 6

2 Answers2

3

As you are already using ggh4x you could achieve your desired result via ggh4x::facetted_pos_scales which allows to set the scale individually for each panel. Doing so you could remove the labels for the upper panel rows. To make this work you also have to set scales="free_x".

As you provided no example data I use some fake data for the reprex. Hence, you have to adjust the condition to filter for the upper panels:

library(ggplot2)
library(ggpubr)
library(ggh4x)

ACE2data2 <- data.frame(
  Dilution = rep(1:20, each = 10),
  Time = 1:10,
  Fluorescence = 1:10
)

ggline(ACE2data2, x = "Time", y = "Fluorescence") +
  labs(x = "Time (min)", y = "RFU Ex/Em 320/420nm") +
  theme(axis.title.x = element_text(size = 22)) +
  theme(axis.title.y = element_text(size = 22)) +
  facet_wrap2(~ Dilution,
              nrow = 5,
              ncol = 4,
              axes = "all", scales = "free_x") +
  force_panelsizes(rows = unit(4, "cm"), cols = unit(4, "cm")) +
  #coord_cartesian(ylim = c(0, 10000)) +
  theme(strip.text.x = element_blank(), strip.background = element_blank()) +
  facetted_pos_scales(x = list(
    (Dilution > 16) ~ scale_x_continuous(),
    (!Dilution > 16) ~ scale_x_continuous(labels = NULL)
  ))

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 2
    Nice suggestion! Just wanted to add that the data agnostic way of achieving the same thing is using `ROW == max(ROW)` and `ROW != max(ROW)` as the left hand side of the formulas. – teunbrand Sep 22 '22 at 19:36
2

If your scales are fixed, the easier solution is to use remove_labels = "all".

Shamelessly stealing stefan's dummy data:

library(ggplot2)
library(ggpubr)
library(ggh4x)

ACE2data2 <- data.frame(
  Dilution = rep(1:20, each = 10),
  Time = 1:10,
  Fluorescence = 1:10
)

ggline(ACE2data2, x = "Time", y = "Fluorescence") +
  labs(x = "Time (min)", y = "RFU Ex/Em 320/420nm") +
  theme(axis.title.x = element_text(size = 22)) +
  theme(axis.title.y = element_text(size = 22)) +
  facet_wrap2(
    ~ Dilution, nrow = 5, ncol = 4,
    axes = "all", remove_labels = "all"
  ) +
  force_panelsizes(rows = unit(4, "cm"), cols = unit(4, "cm")) +
  theme(strip.text.x = element_blank(), 
        strip.background = element_blank())

teunbrand
  • 33,645
  • 4
  • 37
  • 63
  • 1
    Haha. This is the package author advantage. (; And thx for teaching me about `ROW`. – stefan Sep 22 '22 at 19:39
  • 1
    BTW: I added a tag and tag wiki for ggh4x and shamelessy copied and pasted from the README. Feel free to edit and/or extend. – stefan Sep 22 '22 at 19:42
  • 1
    There is also `COL` and `PANEL` if you'd ever need to use those. Anyway, next version is gonna get `scale_x_facet(ROW == 1, ...)` syntax added, so could probably dispense with the awkwardness of `facetted_pos_scales()`. – teunbrand Sep 22 '22 at 19:43
  • Thx. Will check it out and keep it in mind. But will probably need some time to switch to the new API. (: Was the same when switching from `gather` to `pivot_longer`. – stefan Sep 22 '22 at 20:02