Separate Boxplots with groups

I have the following boxplots.
How can I separate these boxplots into four group of boxplots.
Top row content separate boxplots of Jerry and Tom showing X and y
Bottom row content separate boxplots of Jerry and Tom showing a and b.

suppressPackageStartupMessages({
  library(dplyr, warn.conflicts = FALSE)
  library(data.table)
  library(ggplot2)
  library(tidyr)
})
dat=data.frame(
  name=c(rep("Tom",4),rep("Jerry",4)),
  Address=c(rep(c("X","y","a","b"),2)),
  Price=c(86,84,45,57,85,81,35,41)
)

dat=dat %>% 
  mutate(Address=factor(Address, levels =unique(Address)))

dat %>%
  group_by(name) %>%
  ggplot(aes(x = Address, y = Price, fill = Address)) +
  geom_boxplot(fatten = 1,outlier.size = 0.8,lwd=0.7) +
  facet_wrap(~ name)

Is something like this:

dat %>%
  ggplot(aes(x = Address, y = Price, fill = Address)) +
  geom_boxplot(fatten = 1, outlier.size = 0.8, lwd = 0.7) +
  facet_grid(rows = vars(name), cols = vars(Address))

# maybe is better make a geom_point(), because you have only a number in Price and boxplot dont look very well

Thank you for your response. This loooks okay. However, I want to remove the unused x-axis names.
For instance, Only in first plot and b at last boxplot.
moreover, I was trying to use replex my problem with small sample size.

I think you need to do some testing manually. For example this could give you a hint on how to get started

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.