使用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)
ggplot2需要箱图的x和y变量。这是制作单个箱线图的方法
ggplot(data = mpg, aes(x = "", y = displ)) +
geom_boxplot() +
theme(axis.title.x = element_blank())
Run Code Online (Sandbox Code Playgroud)