0

这个 R 代码:

avector <- as.vector(top.links.added.overall$Amount)
x <- as.vector(top.links.added.overall[order(avector),])
x$Amount <- factor(x$Amount)
x$color[x$Amount == 100] <- "red"
x$color[x$Amount == 500] <- "blue"
x$color[x$Amount == 1000] <- "darkgreen"
dotchart(x$Amount,
         labels = row.names(x),
         cex=.7,
         groups = x$Amount,
         gcolor = "black",
         color = x$color,
         pch=19,
         main = "Gas Mileage for Car Models\ngrouped by cylinder",
         xlab = "Miles Per Gallon")

返回此错误:

Error in dotchart(x$Amount, labels = row.names(x), cex = 0.7, groups = x$Amount,  : 
  'x' must be a numeric vector or matrix

这是 top.links.added.overall 的数据文件:

Amount,Name
1000,Google
500,Cnn
100,Yahoo

'x' 是一个向量,那么是什么导致了这个错误?

4

1 回答 1

2

删除转换为因子x$Amount <- factor(x$Amount) 并进行小的更改

dotchart(x$Amount,
     labels = row.names(x),
     cex=.7,
     groups = factor(x$Amount),
     gcolor = "black",
     color = x$color,
     pch=19,
     main = "Gas Mileage for Car Models\ngrouped by cylinder",
     xlab = "Miles Per Gallon")

可能这会对你有所帮助。

于 2013-04-20T18:18:18.380 回答