如何绘制一个boxplot而不指定x轴? [英] How do you draw a boxplot without specifying x axis?

查看:416
本文介绍了如何绘制一个boxplot而不指定x轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用一个简单的命令,基础图形可以很好地绘制箱形图。

  data(mtcars)
boxplot(mtcars $ m $)


但是 qplot 需要y轴。我怎样才能实现与qplot相同的基本图形boxplot并没有得到这个错误?
$ b $ pre $ $ c $ qplot(mtcars $ mpg,geom = 'boxplot')
错误:stat_boxplot需要以下缺失美学:y


解决方案

您必须为 x 提供一些虚拟值。 theme()元素用于删除x轴标题和刻度。

  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())

或者使用<$ c
$ b $ p $ q $ q $ q $($) mtcars,geom ='boxplot')


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

data(mtcars)
boxplot(mtcars$mpg)

But qplot requires y axis. How can I achieve with qplot the same like base graphics boxplot and not get this error?

qplot(mtcars$mpg,geom='boxplot')
Error: stat_boxplot requires the following missing aesthetics: y

解决方案

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')

这篇关于如何绘制一个boxplot而不指定x轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆