user666
user666

Reputation: 1

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?

Upvotes: 0

Views: 98

Answers (1)

Martin Wettstein
Martin Wettstein

Reputation: 2894

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

Upvotes: 1

Related Questions