R: plotting posterior classification probabilities of a linear discriminant analysis in ggplot2

前端 未结 2 935
小鲜肉
小鲜肉 2020-12-24 08:37

Using ggord one can make nice linear discriminant analysis ggplot2 biplots (cf chapter 11, Fig 11.5 in \"Biplots in practice\" by M. Greenacre), as

2条回答
  •  心在旅途
    2020-12-24 08:53

    I suppose the easiest way will be to show the posterior probabilities. It is pretty straightforward for your case:

    datPred$maxProb <- apply(predict(fit)$posterior, 1, max)
    ggplot(datPred, aes(x=LD1, y=LD2) ) +
      geom_raster(data=df, aes(x=x, y=y, fill = factor(class)),alpha=0.7,show_guide=FALSE) +
      geom_contour(data=df, aes(x=x, y=y, z=classnum), colour="red2", alpha=0.5, breaks=c(1.5,2.5)) +
      geom_point(data = datPred, size = 3, aes(pch = Species,  colour=Species, alpha = maxProb)) +
      scale_x_continuous(limits = ld1lim, expand=c(0,0)) +
      scale_y_continuous(limits = ld2lim, expand=c(0,0)) +
      scale_fill_manual(values=colorslight, guide=F)
    

    You can see the points blend in at blue-green border.

提交回复
热议问题