以高度回归的Barplot必须是矢量或矩阵'

时间:2016-08-10 13:07:02

标签: r

我已将xy变量添加为

x = c(1, 2, 3, 4, 5, 6, 7, "8-14", ">14")
y = c(70, 43, 25, 10, 20, 72, 87, 32, 9)

当我输入命令

barplot(y~x, mainlab= "Duration of car hire period for customers", 
  xlab= "Number of Days Rented", ylab= "Frequency")

它回来了

  

barplot.default出错(y~x,mainlab ="客户的租车期限为#34;,:     '高度'必须是向量或矩阵

有人可以解释一下吗?

1 个答案:

答案 0 :(得分:3)

试试这个:

x= c("1", "2", "3", "4", "5", "6", "7", "8-14", ">14")
y= c(70, 43, 25, 10, 20, 72, 87, 32, 9)


barplot(y, mainlab= "Duration of car hire period for customers", xlab= "Number of Days Rented", ylab= "Frequency",
        names.arg= x)

输出:

enter image description here