Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
基本图形可以使用简单的命令很好地绘制箱线图
data(mtcars) boxplot(mtcars$mpg)
但qplot需要y轴。如何使用 qplot 实现与基本图形箱线图相同的功能并且不会出现此错误?
qplot
qplot(mtcars$mpg,geom='boxplot') Error: stat_boxplot requires the following missing aesthetics: y
您必须为x. theme()元素用于删除 x 轴标题和刻度。
x
theme()
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()
qplot(factor(0),mpg,data=mtcars,geom='boxplot')
您还可以使用latticeExtra, 混合boxplot语法和ggplot2-like主题:
latticeExtra
boxplot
ggplot2-like
bwplot(~mpg,data =mtcars, par.settings = ggplot2like(),axis=axis.grid)
您可以将 x 美学设置为factor(0)并通过删除不需要的标签来调整外观:
factor(0)
ggplot(mtcars, aes(x = factor(0), mpg)) + geom_boxplot() + scale_x_discrete(breaks = NULL) + xlab(NULL)