只是想在R中制作直方图

时间:2014-06-17 05:38:19

标签: r histogram

wayne <- c(46, 49, 64, 70, 72, 73, 73, 77, 78, 79, 79, 79, 81, 81, 81, 81,
           81, 82, 82, 84)
hist(wayne, 7)
hist(wayne, breaks=7)
这就是我所拥有的一切。试图制作一个包含7个中断的直方图,但不断收到错误:

hist.default(wayne, breaks = 7) : 'x' must be numeric

1 个答案:

答案 0 :(得分:1)

试试这个

wayne <- c(46, 49, 64, 70, 72, 73, 73, 77, 78, 79, 79, 79, 81, 81, 81, 81, 81, 82, 82, 84)
breaks <- 7 # By doing this you can check if R is reading the value as numeric as shown in the next line
is.numeric(breaks) # R should output "TRUE" and you can now plot your histogram although you should note that R decides the best number of breaks and you can only suggest a number - it may not take that number! 
hist(wayne, breaks) 

这会产生8个休息时间。 为确保您的直方图有7个中断,您可以执行以下操作:

wayne <- c(46, 49, 64, 70, 72, 73, 73, 77, 78, 79, 79, 79, 81, 81, 81, 81, 81, 82, 82, 84)
breaks <- c(46, 52.3, 58.6, 64.9, 70.6, 76.9, 83.2, 89.5)
hist(wayne,breaks)

这创建了一个包含7个中断的直方图