简体   繁体   中英

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:

Error in hist.default(group, las = 1, main = "Frequency", xlab = "group (quantity)"): 'x' must be numeric

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. 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).

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM