library(ggplot2)
DF <- data.frame(site = rep(LETTERS[1:7], each=20), y = runif(7*20))
This Dataframe has 7 Letters(Categories). Is there a way to make boxplot for only A and B (for any 2 categories) categories side by side without transforming the dataset. I trying with the below code but not sucessful
You can filter the dataset before sending it to the ggplot, or filter the data just when you load this into the ggplot-call.
#option 1
filter(DF, site == "A" | site == "B") %>%
ggplot() + geom_boxplot(aes(x = site, y = y))
# option 2
ggplot(data = filter(DF, site == "A" | site == "B")) +
geom_boxplot(aes(x = site, y = y))