I am trying to model output data from the "mixtools" package in a similar manner to how jhoward did here with minor changes. The examples provided work as expected and his solution works with my data, however the fitted distributions seem...tilted.
Notice how both distributions are angled above the x axis slightly.
Using an artificial dataset doesn't show the problem anymore.
`sample.ratio`=c(rnorm(120000,0.386,0.0842),rnorm(200000,0.653,0.1153))
`mixmdl_k2.sample`=normalmixEM(`sample.ratio`, k=2)
ggplot_mixEM <- function(EM) {
require(ggplot2)
x <- with(EM,seq(min(x),max(x),len=1000))
pars <- with(EM,data.frame(comp=colnames(posterior), mu, sigma,lambda))
em.df <- data.frame(x=rep(x,each=nrow(pars)),pars)
em.df$y <- with(em.df,lambda*dnorm(x,mean=mu,sd=sigma))
ggplot(data.frame(x=EM$x),aes(x,y=..density..)) +
geom_histogram(fill=NA,color="black")+
geom_polygon(data=em.df,aes(x,y,fill=comp),color="grey50", alpha=0.5)+
scale_fill_discrete("Component\nModes",labels=format(em.df$mu,digits=3))+
geom_density(color="red",linetype="dotted")
}
ggplot_mixEM(`mixmdl_k2.sample`)
. The distribution fills are now level, though they are also no longer constrained to the (0,1) interval.
About my data: it ranges explicitly from 0-1, and the bimodal distribution modeled by mixtools is expected. Increasing the x scale with scale_x_continuous(limits=c(-0.1,1.1))
didn't solve the issue. The first solution from the link above, provided by Spacedman, also worked on my data, but gave the same "tilted plot" results.
Does anyone know why this is happening and how to fix this tilt? Is there a way to force extend the shading to the x axis?
Thank you.
Edit: added in sample code.