这是如何在混合高斯模型上绘制 ggplot 曲线的一些片段
ggplot(mix_example) + geom_histogram(aes(x = x, y = ..density..)) +
stat_function(geom = "line", fun = fun_prop, color="red",
args = list(mean = comp_1[1], sd = comp_1[2],
proportion = proportions[1])) +
stat_function(geom = "line", fun = fun_prop, color="green",
args = list(mean = comp_2[1], sd = comp_2[2],
proportion = proportions[2]))+
stat_function(geom = "line", fun = fun_prop, color="blue",
args = list(mean = comp_3[1], sd = comp_3[2],
proportion = proportions[3]))
上面的 Snippets 添加了 3 个 stat 函数以在混合分布密度上绘制一条集群线,参数 (args) 来自flexmix 模型,该模型由每个混合分布集群的均值和标准差组成,我想将其扩展为“ n 度”,因此它适用于绘制n 条混合分布的 n 簇的 n 条线。但我想知道是否有任何方法可以在不一一添加 stat_function 的情况下做到这一点