I'm new to R, and I've been running into trouble trying to make a histogram with a density line.
My data has 3 subsets of data, and the 1st subset gives me an error when I try to make a histogram.
Sample code:
dataset<- read.table(file.choose(), header = T, sep="\t")
g1<- dataset$Average..01
hist(g1)
Error message: Error in hist.default(dataset$Average..01,: 'x' must be numeric
Yet, for the other two subsets of data the histogram is able to be plotted, Although the plot shows, the density line is below the x-axis. Sample code:
hist(dataset$Average..10)
xfit<-seq(min(dataset$Average..10),max(dataset$Average..10),length=40)
yfit<-dnorm(xfit,mean=mean(dataset$Average..10),sd=sd(ataset$Average..10))
yfit <-yfit*diff(dataset$Average..10[1:2])*length(dataset$Average..10)
lines(xfit, yfit, col="red", lwd=3)
I'm not too sure what's going on, or how to fix this. Any advice would be much appreciated!
dput(dataset). - Alex