在相同的情节中,每个都有自己的正常分布的每个直方图3个直方图?

时间:2017-11-09 01:44:44

标签: r csv histogram normal-distribution

如何在同一个图上将3个直方图与其自身的正态分布重叠?有这样的图表吗?图像显示分子移动100,1000和10000次时的最后几点:

image

我已经在R上拥有了自己的正态分布直方图。我使用了这个代码......

 # histograms
 b=read.csv("pruebab.csv")
 b=b$pruebab
 hist(b, freq = F,
      ylab = "Densidad",
      xlab = "Alturas (cm)", main = "")
 curve(dnorm(x, mean(b), sd(b)),
       col = "blue", lwd = 3, add = TRUE)
 hist(b, freq = F,
      ylab = "casualities",
      xlab = "meters", main = "")
 curve(dnorm(x, mean(b), sd(b)),
       col = "blue", lwd = 3, add = TRUE)

我的直方图及其分布函数的一个例子:

image

2 个答案:

答案 0 :(得分:1)

您可以尝试ggplot2

library(tidyverse) 
df <- data.frame(x = rnorm(1000, 0, 1), y = rnorm(1000, 0, 3), z = rnorm(1000, 0, 5))
df <- melt(df)
ggplot(df, aes(x = value, y = ..count.., group = variable, fill = variable)) +
  geom_histogram(alpha = .6, binwidth = .5) +
  geom_density(alpha = .1, size = 1.2, aes(color = variable)) +
  theme_minimal()

enter image description here

答案 1 :(得分:0)

你是这样做的:

h2 = rnorm(1000,4)
h1 = rnorm(1000,6)

# Histogram Grey Color
hist(h1, col=rgb(0.1,0.1,0.1,0.5),xlim=c(0,9), ylim=c(0,0.4), main="Overlapping Histogram", prob=T)
curve(dnorm(x, mean=mean(h1), sd=sd(h1)),xlim=c(0,10), ylim=c(0,200), add=TRUE,
      col = "blue", lwd = 3)

hist(h2, col=rgb(0.8,0.8,0.8,0.5), add=T,prob = T)
curve(dnorm(x, mean(h2)),
      col = "red", lwd = 3, add = TRUE)

你错过了第二和第三个直方图中的add = TRUE