[英]trouble drawing a histogram in R - x must be numeric
i am trying to draw a histogram in R but it tells me the error:我正在尝试在 R 中绘制直方图,但它告诉我错误:
Error in hist.default(group, las = 1, main = "Frequency", xlab = "group (quantity)"): 'x' must be numeric
hist.default(group, las = 1, main = "Frequency", xlab = "group (quantity)") 中的错误:'x' 必须是数字
below is my code:下面是我的代码:
CD = read.csv("Bees.csv")
View(CD)
Survey = read.csv("Bees.csv", na.strings = c(""," ","NA"))
attach(Survey)
View(Survey)
hist(group, las=1, main="Frequency", xlab="group (quantity)")
library(FSA)
op = group(oma=c(0,0,1.5,0), mar=c(3,3,2,1))
hist(group ~ mass,
las=1,
nrow=2, ncol=1,
cex.main=0.9, cex.lab=0.8, cex.axis=0.8,
mgp=c(1.8,0.6,0),
xlab="group (quantity)" # x-axis title
)
mtext("Frequency", side=3, outer=TRUE, font=2)
par(op)
i wrote it all in, but the error actually occurs early on at:我把它全部写进去了,但错误实际上发生在早期:
hist(group, las=1, main="Frequency", xlab="group (quantity)")
Could someone please help me to see what I am doing wrong?有人可以帮我看看我做错了什么吗?
The variable group
does not seem to be a numeric variable.变量
group
似乎不是数字变量。 It might be a character vector, which may not be plotted as a histogram.它可能是一个字符向量,可能不会绘制为直方图。 Use
summary(group)
to check whether there actually are numeric values (the summary should show min, max, median and mean if it is numeric).使用
summary(group)
检查是否确实存在数值(如果是数值,摘要应显示最小值、最大值、中值和平均值)。
If it does not contain numeric values but characters, a histogram is the wrong diagram type.如果它不包含数值而是字符,则直方图是错误的图表类型。 You might want a barplot.
你可能想要一个条形图。 Draw it by using the syntax:
barplot(table(group))
使用语法绘制它:
barplot(table(group))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.