在下面的代碼中,我構建了一個40x1000的數據框,其中每列中我都有來自參數lambda = 0.2的指數分佈的連續隨機抽取的累積平均值。 我添加了一個額外的列來承載「繪製」的具體數量。 我也計算行平均值作爲df_means。R - 如何覆蓋一組iid RV的平均值
如何在所有模擬房車上添加df_means(作爲黑線)?我不明白ggplot足夠做到這一點。
df <- data.frame(replicate(1000,cumsum(rexp(40,lambda))/(1:40)))
df$draw <- seq(1,40)
df_means <- rowMeans(df)
Molten <- melt(df, id.vars="draw")
ggplot(Molten, aes(x = draw, y = value, colour = variable)) + geom_line() + theme(legend.position = "none") + geom_line(df_means)
我該如何在我的ggplot中添加陰謀(df_means,type =「l」)?
謝謝