Use of ggboxplot

Good afternoon,

I have some struggles to realise 2 boxplot with the ggboxplot function.

I would like to have this kind of boxplots :

So I tried with this :

p <- ggboxplot(Base_donnees_finale, x = "N2O_agricole_MilliersTECO2", y ="Tonne équivalent CO2 à l'ha cultivable")

Add p-value
p + stat_compare_means()

But as a result I have the same boxplots than before even if I use different variables !!!

I just don't know where to put the two variables to make my boxplots.

My data base is called "Base_de_donnee_finale" and my two variables are "N2O_agricole_MilliersTECO2" and "CH4_agricole_MilliersTECO2" and to have a wilcoxon test in it.

Does someone knows how to make the right syntax ?

Kind regards



To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:


I am very sory but I don't know how to select only the two columns I need from my database ...



I notice you quote your code as being

but then you say

Shouldn't your code be

p <- ggboxplot(Base_donnees_finale, x = "N2O_agricole_MilliersTECO2", y ="CH4_agricole_MilliersTECO2")

with CH4_agricole_MilliersTECO2 as the y parameter?

I don't think this is going to produce the desired result because both variables seem to be numerical, and for a similar plot as in the example you would need a factor variable for the x-axis.

I can't be sure without sample data but maybe you would need to reshape your data to a long format with something like this.


Base_de_donnee_finale %>% 
  gather(key = "Parameter", value = "Value", N2O_agricole_MilliersTECO2, CH4_agricole_MilliersTECO2) %>% 
  ggboxplot(Base_donnees_finale, x = "Parameter", y ="Value") +

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