使用ggplot2绘制简单箱线图时出现错误。

3

使用R中的mpg数据,我可以用以下代码绘制“displ”的箱线图:

boxplot(mpg$displ)

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

ggplot(data = mpg, aes(displ)) + geom_boxplot()

我收到了这个错误信息:
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'
1个回答

7

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

ggplot(data = mpg, aes(x = "", y = displ)) + 
  geom_boxplot() + 
  theme(axis.title.x = element_blank())

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接