Looking to solve problem with facet_wrap/facet_grid that isn't resolved with space = "free"
Solution 1:
You can get this easily with lemon::facet_rep_grid(repeat.tick.labels = T)
instead of ggplot2::facet_grid()
.
library(tidyverse)
library(lemon)
b <- structure(list(Race = c("Asian", "Asian", "Asian", "Asian", "Asian",
"Asian", "Asian", "Asian", "Asian", "Asian", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black"),
Symptom = structure(c(10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 10L, 9L,
8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L),
.Label = c("Symptom10", "Symptom9", "Symptom8",
"Symptom7", "Symptom6", "Symptom5", "Symptom4",
"Symptom3", "Symptom2", "Symptom1"),
class = "factor"),
Percentage = c(60L, 50L, 20L, 70L, 90L, 100L, 10L, 30L, 40L, 60L, 40L, 20L, 50L,
50L, 85L, 30L, 30L, 20L, 80L, 40L),
Group = c("Benign", "Benign", "Warning", "Warning", "Warning", "Fatal", "Fatal",
"Fatal", "Fatal", "Fatal", "Benign", "Benign", "Warning", "Warning",
"Warning", "Fatal", "Fatal", "Fatal", "Fatal", "Fatal")),
row.names = c(NA, -20L),
class = c("tbl_df", "tbl", "data.frame"))
ggplot(data=b, aes(x=Percentage, y= Symptom, fill = Race)) +
geom_bar(stat="identity", position=position_dodge()) +
facet_rep_grid(Group~., scales = "free", space = "free", repeat.tick.labels = T)
Created on 2022-01-18 by the reprex package (v2.0.1)