使用ggplot2制作简单的箱线图时出错

Bel*_*ell 2 r ggplot2

使用R中的mpg数据,我可以使用

boxplot(mpg$displ)
Run Code Online (Sandbox Code Playgroud)

但是当我尝试用ggplot制作这个简单的箱线图时,

ggplot(data = mpg, aes(displ)) + geom_boxplot()
Run Code Online (Sandbox Code Playgroud)

我得到这个错误;

Error in seq.default(from = best$lmin, to = best$lmax, by = best$lstep) : 'from' must be of length 1
In addition: Warning messages:
1: Continuous x aesthetic -- did you forget aes(group=...)? 
2: In is.na(data$y) :  is.na() applied to non-(list or vector) of type 'NULL'
Run Code Online (Sandbox Code Playgroud)

Thi*_*rry 5

ggplot2需要箱图的xy变量。这是制作单个箱线图的方法

ggplot(data = mpg, aes(x = "", y = displ)) + 
  geom_boxplot() + 
  theme(axis.title.x = element_blank())
Run Code Online (Sandbox Code Playgroud)