在R中绘制简单的条形图,错误:高度必须是矩阵的向量 [英] Plotting a simple bargraph in R, Error: Height must be a vector of matrix
问题描述
这是我在R中的数据框,
This is my dataframe in R,
New York 8755
Texas 7654
California 6726
Florida 6322
我只希望图形比较并排堆积的条形中的数字,但我还没有做到这一点.我收到错误消息高度必须是矩阵的向量".请提出建议!非常感谢!
I simply want the graph to compare the numbers in a bar stacked side by side.I have not been able to achieve that. I am getting the error "Height must be a vector of Matrix." Please suggest! Thanks a lot!
推荐答案
R在传递变量时无法确定哪个变量是要绘制的整个data.frame.在这种情况下,错误'height'必须是向量或矩阵
告诉您没有给plot函数提供它想要的东西.
R cannot tell which variable is which when you pass it an entire data.frame to plot. In this case, the error, 'height' must be a vector or a matrix
is telling you you didn't give the plot function what it wanted.
对于 barplot
,使用?barplot
会告诉您需要什么:
For a barplot
, using ?barplot
will tell you what is needed:
barplot(高度,宽度= 1,空格= NULL,names.arg = NULL ....
barplot(height, width = 1, space = NULL, names.arg = NULL ....
在您的情况下,您有一个data.frame,在第二列中具有高度,在第一列中具有名称,因此您想这样做:
In your case, you have a data.frame with heights in the second column, and names in the first, so you want to do:
barplot(data[ ,2], names.arg = data[ ,1])
这篇关于在R中绘制简单的条形图,错误:高度必须是矩阵的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!