Home > Software design >  Set Axis Limits of mixfitEM plot
Set Axis Limits of mixfitEM plot

Time:06-17

I want to set limits to the x-axis of the plot of the output of the mixfit function of the mixR package. This output is of class mixfitEM.

Reproducable example: First I simulate a mixture of log normals.

rm(list=ls())
library(mixR)
library("tidyverse")
set.seed(07062022)


N <- 1000
lbda=.5
mu1=1
Del=3
mu2=mu1 Del
components <- sample(1:2,prob=c((1-lbda), lbda),size=N,replace=TRUE)
mus <- c(mu1,mu2)
sds <- sqrt(c(1,.5))

Y <- rlnorm(n=N,meanlog=mus[components],sdlog=sds[components])

Then I try to fit two log normals into this data using mixfit() from mixR. In the first attempt I tried to use the plot() function from the base package; but plot ignores the xlim argument.

mod4 <- mixfit(Y, ncomp = 2, family = 'lnorm')

plot(mod4, title = 'Log-Normal Mixture (2 components)', xlim=c(0,200))

Then I tried to plot with ggplot, which, in theory should be possible according to the enter image description here

  • Related