如何找到用ggplot2创建的两个密度图的交集
来自名为组合式的数据框架的示例
futureChange direction
2009-10-26 0.9980446 long
2008-04-28 1.0277389 not long
2012-07-09 1.0302413 not long
2010-11-15 1.0017247 not long
我使用此代码创建密度图。
ggplot(combined, aes(futureChange, fill = direction))
geom_density(alpha = 0.2)
我试图在R中再现上述函数。分子在时间"t“时有"y”的概率密度函数(pdf)的乘积。omega_t只是权重(现在让我们忽略它)。i代表model_i ( time t )导出的y(以及密度)的每一个预测值。
分母是上述乘积的积分。我的问题是:如何估计密度。要获得变量的密度,需要一些数据点。到目前为止我有这样的想法:
y<-c(-0.00604,-0.00180,0.00292,-0.0148)
forecastsy_model1<-c(-0.0183,0.00685) # respectively time t=1 and t=2 of the forec
我试图在R中实现的图的类型似乎被称为移动分布,as joy plot or as ridgeline plot ? 在Stackoverflow中已经有一个问题,其录制的答案解释了如何使用ggplot:How to reproduce this moving distribution plot with R? 然而,出于学习的目的,我正在尝试仅使用基础R图(无网格、无ggplot、无任何绘图包)来实现相同的效果。 为了开始,我生成了以下假数据: set.seed(2020)
shapes <- c(0.1, 0.5, 1, 2, 4, 5, 6)
dat <- lappl
下面的代码用曲线区域下的颜色填充两种密度: library(ggplot2)
#fake data
dat <- data.frame(dens = c(rnorm(100), rnorm(100, 2, 0.5))
, group = rep(c("C", "P"), each = 100))
#fill the area under the curve
ggplot(dat, aes(x = dens, fill = group)) + geom_density(alpha = 0.75) 如何实现以下两个目
我需要一些帮助来生成一个类似于在这里发布的的图表
我尝试了文章中提到的代码,但是结果并不好看。
我的数据库是这样的:
head(df)
a b c d e f g
1 0.9999994 0.9999994 0.7924445 0.9998647 0.7300587 0.9249790 0.9816021
2 0.9999885 0.9999885 0.6782044 0.9983770 0.6119326 0.9434158 0.9583668
3 1.0000000 1.0000