我希望你们中的一些人能帮助我。我正在使用 x-log 比例在我的直方图中绘制一个正常拟合。我使用对数刻度,因为我的数据的正常直方图有一条长尾。我的代码是这样的..
breaks<- c(0,0.01, 0.05, 0.1,0.2,0.5,1,2,5,10,20,50,100,200,300) #bins
major <- c(0.1,1,10,100)
H <- hist(log10(B),plot=B) #using data "B"
plot(H$mids,H$counts,type="n",
xaxt="n",
xlab="B",ylab="Counts",
main="Histogram of B",
bg="lightgrey"
)
abline(v=log10(breaks),col="lightgrey",lty=2)
abline(v=log10(major),col="lightgrey")
abline(h=pretty(H$counts),col="lightgrey")
plot(H,add=T,freq=T,col="blue")
#Position of ticks
at <- log10(breaks)
#Creation X axis
axis(1,at=at,labels=10^at)
curve(dnorm(x, mean=mean(B), sd=sd(B)), add=TRUE) # 1st try
lines(density(B)) # 2nd try
xfit<-seq(min(B),max(B),length=40) # 3rd try
yfit<-dnorm(xfit,mean=mean(B),sd=sd(B))
yfit<-yfit*diff(H$mids[1:2])*length(B)
lines(xfit, yfit, col="red", lwd=2)
但是第 1 次、第 2 次、第 3 次尝试都不起作用。请告诉我如何在直方图中添加正常拟合。非常感谢您的帮助。萨米