R -0.01*高度中出错:二进制运算符的非数字参数
我试图在CSV文件中为我的数据创建条形图。我使用了以下代码:R -0.01*高度中出错:二进制运算符的非数字参数,r,plot,bar-chart,R,Plot,Bar Chart,我试图在CSV文件中为我的数据创建条形图。我使用了以下代码: dput(head(data))显示数据已成功读取!!但错误仍然存在 正如正确的建议,您必须将As.matrix(data)替换为As.matrix(As.data.frame(data)) 您也可以尝试以下代码: colours <- c("red", "orange", "blue", "yellow", "green","black") data2 <- data.frame(data) barplot(as.mat
dput(head(data))
显示数据已成功读取!!但错误仍然存在 正如正确的建议,您必须将As.matrix(data)
替换为As.matrix(As.data.frame(data))
您也可以尝试以下代码:
colours <- c("red", "orange", "blue", "yellow", "green","black")
data2 <- data.frame(data)
barplot(as.matrix(data2), main="My Barchart", ylab = "Numbers", cex.lab = 1.5, cex.main = 1.4, beside=TRUE, col=colours)
legend("topleft", c("First","Second","Third","Fourth","Fifth","Sixth"), cex=1.3, bty="n", fill=colours)
颜色代码不可复制您所说的代码不可复制是什么意思?这意味着我们无法将您的代码复制并粘贴到我们的R控制台并获取您的错误(我们没有主题
)。为了帮助你,我们需要能够做到这一点。这是涵盖在它的工作,但在我这边的错误!!当然有。您拥有主题
数据集。我们没有。如果您只使用来自dput(data)
的结果作为数据的赋值,效果会更好。调试问题需要重复。你看过上面的链接了吗?
Error in -0.01 * height : non-numeric argument to binary operator
colours <- c("red", "orange", "blue", "yellow", "green","black")
data2 <- data.frame(data)
barplot(as.matrix(data2), main="My Barchart", ylab = "Numbers", cex.lab = 1.5, cex.main = 1.4, beside=TRUE, col=colours)
legend("topleft", c("First","Second","Third","Fourth","Fifth","Sixth"), cex=1.3, bty="n", fill=colours)