Boxplot in ggpubr

This may be a stupid question, but I don't understand the difference. I am trying create plot with two columns Last grade and First grade, something like this:

boxplot(t_agregation$First_Grade, t_agregation$Last_Grade, xlab="First and Last Grade")

And I get what I expected:

Now I try this with ggpubr:

ggboxplot(t_agregation,y="Last_Grade", x="First_Grade")

And I get this:

I realize I'm missing something and I'm not setting the parameters right, what am I doing wrong?

Hi Teodor,

This is because in the function ggboxplot() you need the data in long format. I write an example:

set.seed(123)
library(ggpubr)
#> Loading required package: ggplot2
library(tidyr)

grades <- data.frame(first_grade = sample(1:10, 15, replace = TRUE),
                     last_grade = sample(1:10, 15, replace = TRUE))

grades_long <- pivot_longer(grades, 1:2)
grades_long
#> # A tibble: 30 x 2
#>    name        value
#>    <chr>       <int>
#>  1 first_grade     3
#>  2 last_grade      3
#>  3 first_grade     3
#>  4 last_grade      8
#>  5 first_grade    10
#>  6 last_grade     10
#>  7 first_grade     2
#>  8 last_grade      7
#>  9 first_grade     6
#> 10 last_grade     10
#> # … with 20 more rows
ggboxplot(grades_long, x = "name", y = "value")

ggboxplot

Created on 2021-04-22 by the reprex package (v2.0.0)

Hope that helps.

Greetings.

2 Likes

This topic was automatically closed 7 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.