boxplot for a single variable without categories

Hello,
I am wondering if there is a way to create boxplot for a single variable, without adding x = (category)

however, this function requires to have x variable... Is there a way to rather have the name of y variable under x axis and no categories?

boxplot_func <- function(y) {
ggplot(mtcars)+
aes(y= y)+
geom_boxplot()+
stat_summary(fun="mean",geom="point", pch=3,color="red")+
geom_jitter(color= "grey")+
theme_bw()
}

Is this close to what you are trying to do?

library(ggplot2)
boxplot_func <- function(y) {
  ggplot(mtcars, aes_string(x = 1, y= y))+
    geom_boxplot()+
    stat_summary(fun="mean",geom="point", pch=3,color="red")+
    geom_jitter(color= "grey")+
    labs(x = y) +
    theme_bw() +
    theme(axis.text.x = element_blank())
    
}
boxplot_func("mpg")

Created on 2020-07-16 by the reprex package (v0.3.0)

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

this is exactly it. Thank you very much!