GGplot错误:ggplot2不知道如何处理类数字的数据>

时间:2016-10-12 18:57:17

标签: r ggplot2

我是Rstudio的新手。我应该绘制一个新变量的直方图。变量可能是一个因子变量。我用as.numeric来重新编码。我的代码如下:

anes$libcpo_final<-revalue(anes$libcpo_self, c("-9. Refused" =-9, "-8. Don't know"=-9, "-7. Deleted due to partial (post-election) interview" =-9, "-6. Not asked, unit nonresponse (no post-election interview)"=-9, "-2. Haven't thought much {do not probe}"=-9, "1. Extremely liberal" =-3, "2. Liberal"=-2,"3. Slightly liberal"=-1,"4. Moderate; middle of the road"=0,"5. Slightly conservative"=1,"6. Conservative"=2,"7. Extremely conservative"=3))

库(GGPLOT2)

练习1 B:

libcpo_new<-as.numeric(anes$libcpo_final)
hist(libcpo_new)
ggplot(libcpo_new, aes(x=libcpo_new))

这是错误:

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

0 个答案:

没有答案