Plot the estimated clusters
At this point, you have discovered the two cluster in the data frame gaussian_sample
. In this exercise, you will visualize how the estimated clusters for the iteration 10 fit the data. The vectors means_iter10
and props_iter10
are already saved in the environment.
To this end, you will use the ggplot2
function called stat_function()
, which lets you superimpose a function on top of an existing plot. The function you will use a created curve function called fun_gaussian()
which takes as arguments the mean and the proportion of the Gaussian.
Este exercício faz parte do curso
Mixture Models in R
Instruções do exercício
Plot the histogram in density mode of the variable x
and add the estimated curves using stat_function()
in combination with the function fun_gaussian()
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
___ %>%
ggplot() + geom_histogram(aes(x = ___, y = ___), bins = 200) +
stat_function(geom = "line", fun = fun_gaussian,
args = list(mean = means_iter10[1], proportion = ___[1])) +
stat_function(geom = "line", fun = fun_gaussian,
args = list(mean = ___[2], proportion = props_iter10[2]))