How do you draw a boxplot without specifying x axis?

后端 未结 3 1285
无人及你
无人及你 2020-12-19 03:26

The base graphics can nicely plot a boxplot using a simple command

data(mtcars)
boxplot(mtcars$mpg)

相关标签:
3条回答
  • 2020-12-19 03:44

    You have to provide some dummy value to x. theme() elements are used to remove x axis title and ticks.

    ggplot(mtcars,aes(x=factor(0),mpg))+geom_boxplot()+
       theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())
    

    Or using qplot() function:

    qplot(factor(0),mpg,data=mtcars,geom='boxplot')
    

    0 讨论(0)
  • 2020-12-19 04:08

    You can also use latticeExtra, to mix boxplot syntax and ggplot2-like theme:

    bwplot(~mpg,data =mtcars,
            par.settings = ggplot2like(),axis=axis.grid)
    

    enter image description here

    0 讨论(0)
  • 2020-12-19 04:10

    you can set the x aesthetics to factor(0) and tweak the appearance by removing unwanted labels:

    ggplot(mtcars, aes(x = factor(0), mpg)) +
        geom_boxplot() + 
        scale_x_discrete(breaks = NULL) +
        xlab(NULL)
    

    0 讨论(0)
提交回复
热议问题