当我绘制两个图形(一个函数和一个柱状图)时,我遇到了轴的问题。

我已经尝试将axes = FALSE。尽管它不能很好的工作。
下面是我的代码:
n = 64
p = 0.5
tailleEchantillon<-1000
m = n * p
sigma = sqrt(n * p * (1 - p))
borne_sup = m+7*sigma
borne_inf = m-7*sigma
x = 0:n
echantillon = rbinom(tailleEchantillon,n,p)
tabEffectifs = NULL
for (i in x) {tabEffectifs = c(tabEffectifs,length(echantillon[echantillon == i]))}
print("Tableau des effectifs")
print(table(echantillon,deparse.level=2))
texteLegende1<-bquote(p == .(p))
texteTitre1 = ""
barplot(tabEffectifs,las=1,names.arg=x,col="blue",ylim=c(0,(tailleEchantillon/4)),legend.text=texteLegende1,main=texteTitre1,xlab="k",ylab="Effectifs",cex.main=1)
tabFrequences = tabEffectifs/tailleEchantillon
plot(function(x) dnorm(x, m, sigma), borne_inf, borne_sup, legend.text="Courbe loi normale", ylim=c(0,0.10), xlab="x", ylab="prob")
par(new = T)
barplot(tabFrequences,las=1,names.arg=x, col="red", ylim=c(0,0.10),legend.text=texteLegende2,main=texteTitre2,xlab="k",ylab="Densites",cex.main=1)有没有人知道我怎样才能避免这个叠加轴线的问题?谢谢。
发布于 2018-12-20 16:24:04
问题是,通常情况下,这条线必须遵循条形图,但这里不是这样。我不明白为什么,因为在正常的定律中,最大值应该是x=m,而在这个m= 36,而不是25。
我认为这两个(直线和柱状图)不具有相同的x轴。你对此有什么解决方案吗?谢谢。
发布于 2018-12-20 05:42:03
尝试如下所示:
barplot(tabFrequences,las=1,names.arg=x, col="red", ylim=c(0,0.10))
lines(x, dnorm(x,m, sigma), col ="blue")这样,您只是叠加了线条,而不是整个图形。

为了完全公开,我只回答了你关于密谋的问题。这个发行版似乎有些新奇的东西。也许你的模拟出了什么问题?
https://stackoverflow.com/questions/53858928
复制相似问题