基本图形可以使用简单的命令
很好地绘制箱线图data(mtcars)
boxplot(mtcars$mpg)
但是qplot
需要y轴。如何使用qplot与基本图形boxplot相同而不会出现此错误?
qplot(mtcars$mpg,geom='boxplot')
Error: stat_boxplot requires the following missing aesthetics: y
答案 0 :(得分:17)
您必须为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())
或使用qplot()
功能:
qplot(factor(0),mpg,data=mtcars,geom='boxplot')
答案 1 :(得分:2)
您还可以使用latticeExtra
混合boxplot
语法和ggplot2-like
主题:
bwplot(~mpg,data =mtcars,
par.settings = ggplot2like(),axis=axis.grid)
答案 2 :(得分:1)