Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在ggplot2中绘制密度而不是直线?_R_Ggplot2_Gmm - Fatal编程技术网

R 如何在ggplot2中绘制密度而不是直线?

R 如何在ggplot2中绘制密度而不是直线?,r,ggplot2,gmm,R,Ggplot2,Gmm,如何使ggplot2::stat_函数生成密度图而不是geom=“line” 我的表格$distance是数字 mixmdl <- mixtools::normalmixEM(My_table2$Distances, k = 4) plot_GMM(mixmdl,4) mixmdl$posterior x <- mixmdl$x x <- data.frame(x) GMMplot <- ggplot2::ggplot(data.frame(x)) + ggplo

如何使ggplot2::stat_函数生成密度图而不是geom=“line”

我的表格$distance
是数字

mixmdl <- mixtools::normalmixEM(My_table2$Distances, k = 4)

plot_GMM(mixmdl,4)
mixmdl$posterior
x <- mixmdl$x
x <- data.frame(x)

GMMplot <- ggplot2::ggplot(data.frame(x)) +
  ggplot2::geom_density(ggplot2::aes(x), color="black",alpha = .2) +
  ggplot2::stat_function(geom = "line", fun = plot_mix_comps,args = list(mixmdl$mu[1], 
  mixmdl$sigma[1], lam = mixmdl$lambda[1]),colour = "blue1",alpha = 1.5) +
  xlab("distance (nm)")+theme_bw()+
  theme(axis.title.y=element_blank(),
  axis.text.y=element_blank(),
  axis.ticks.y=element_blank(),
  legend.position = "none")+
  ggplot2::stat_function(geom = "line",fun = plot_mix_comps,args = list(mixmdl$mu[2], mixmdl$sigma[2], lam = mixmdl$lambda[2]),colour = "blue2")+
  ggplot2::stat_function(geom = "line",fun = plot_mix_comps,args = list(mixmdl$mu[3], mixmdl$sigma[3], lam = mixmdl$lambda[3]),colour = "blue3")+
  ggplot2::stat_function(geom = "line",fun = plot_mix_comps,args = list(mixmdl$mu[4], mixmdl$sigma[4], lam = mixmdl$lambda[4]),colour = "blue4")+ylim(0.00,0.043)
GMMplot

mixmdl请
dput()