Search code examples
rggplot2facet-wrap

ggplot : make a facet-wrap for specific value of two variables


I have a data frame (DF) that is structured like this :

RMS | measure | parameter | tirage | case | nombre

Here is the link to my data frame. I want to plot RMS as my y Vs. nombreas my x for different measure but for a specific value of parameter as well as a specific value of case. I have already tried this :

ggplot(data = DF, aes(factor(nombre), RMS, case = 2, parameter = 1)) +
geom_boxplot() +  
facet_wrap( ~ measure, scales = "fixed", ncol = 1) 

But it does not work. It still plots all data corresponding to all values of case and all values of measure. I searched a bit and I saw that if it was just one variable (either case or measure), I could simply use group = specific value. But since we have two variables, I don’t know how I should specify this. Your help would be greatly appreciated.


Solution

  • library(dplyr); library(ggplot2)
    ggplot(data = DF %>% filter(case == 2, parameter == 1), 
           aes(factor(nombre), RMS)) +
    geom_boxplot() +  
    facet_wrap( ~ measure, scales = "fixed", ncol = 1)