问题
I have a dataset with five variables: Dataset
, Biome
, Species
, Growth.form
and N.content
. I'm trying to make a histogram with the N.content
variable only, but I'm getting the error:
Error in hist.default(Ndata, xlab = "Blader", ylab = "N.content", main = "N.content", :
'x' must be numeric
What am I doing wrong?
Here's my script:
mydata <- read.table("Leaf N content.txt", sep="\t", header=TRUE)
summary(mydata)
class(mydata)
str(mydata)
table(mydata$Growth.form)
table(mydata$Biome)
Sumdata <- as.data.frame(with(mydata, table(Biome, Growth.form)))
table(Sumdata)
Ndata <- subset(mydata, select=c(N.content))
logdata <- log(Ndata)
par(mfrow=c(1,2))
hist(Ndata, xlab="Blader", ylab="N.content", main="N.content", col= "red")
hist(logdata, xlab="Blader", ylab="N.content", main="N.content", col= "red")
回答1:
mydata
is a data.frame. subset(mydata, select=c(N.content))
returns a data.frame. hist
expects a (numeric) vector. Use Ndata <- mydata$N.content
to select a column vector.
来源:https://stackoverflow.com/questions/33347560/x-must-be-numeric-histogram-in-r