矢量,ggplot2 不知道如何处理 class 数字的数据

Vector, ggplot2 doesn't know how to deal with data of class numeric

我正在尝试使用 ggplot2 制作一个简单的箱线图。我有一个带有数字的向量,但是当我输入代码时,会出现此错误消息:

Error: ggplot2 doesn't know how to deal with data of class numeric.

这是什么意思?

代码:

vector1 <- c(x1, x2, x3, ...)
library(ggplot2) 
ggplot(vector1, aes(x=x, y=value)) + boxplot()

您可以按如下方式使用qplot

qplot(1,vector1, geom="boxplot")

或者(正如@scoa 指出的那样)concert vector1 to a data.frame as ggplot 仅在 data.frame 上运行而不在向量上运行。 qplot 是非常简单的绘图的便利包装器。