使用R中的mpg数据,我可以制作一个' displ'的盒子图。与
boxplot(mpg$displ)
但是当我尝试使用ggplot创建这个简单的boxplot时,
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'
答案 0 :(得分:5)
ggplot2
需要箱形图的x
和y
变量。以下是如何制作单个箱图
ggplot(data = mpg, aes(x = "", y = displ)) +
geom_boxplot() +
theme(axis.title.x = element_blank())