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

*爱你&永不变心* 提交于 2019-12-24 00:57:45

问题


I'm trying to make a simple boxplot with ggplot2. I've got a vector with numbers but when I type in the code an this error message appears:

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

What does that mean?

Code:

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

回答1:


You can use qplot as follows:

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

Or (as @scoa pointed out) concert vector1 to a data.frame as ggplot operates only on data.frames and not on vectors. qplot is a convenience wrapper for very simple plots.



来源:https://stackoverflow.com/questions/35525240/vector-ggplot2-doesnt-know-how-to-deal-with-data-of-class-numeric

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!