如何在R中绘制直方图和饼图?

时间:2017-11-23 21:07:39

标签: r histogram

我已经关注了代码:

table_final = data.frame(table1$Text, table1$value,table2$value, table3$value) 
hist(table_final$Positive,col=rainbow(10))
hist(table_final$Negative,col=rainbow(10)) 
hist(table_final$Score, col=rainbow(10))

slices <- c(sum(table_final$Positive), sum(table_final$Negative)) 
labels <- c("Positive", "Negative") 
library(plotrix) 
pie3D(slices,labels = labels,col=rainbow(length(labels)),explode=0.00,main="Sentiment Analysis")

我收到了以下错误:

hist(table_final$Positive, col=rainbow(10))

Error in hist.default(table_final$Positive, col = rainbow(10)) : 
  'x' must be numeric

hist(table_final$Negative, col=rainbow(10))

Error in hist.default(table_final$Negative, col = rainbow(10)) : 
  'x' must be numeric

hist(table_final$Score, col=rainbow(10))
  Error in hist.default(table_final$Score, col = rainbow(10)) : 
  'x' must be numeric

pie3D(slices, labels = labels, col=rainbow(length(labels)),
      explode=0.00, main="Sentiment Analysis")

Error in seq.default(start, end, by = angleinc) : 
  'to' must be a finite number

请帮助!!

1 个答案:

答案 0 :(得分:0)

对于直方图,请尝试

as.numeric(table_final$Positive)