Plotting a bivariate to multiple factors in R

后端 未结 3 2154
终归单人心
终归单人心 2021-01-06 12:14

First of all, I\'m still a beginner. I\'m trying to interpret and draw a stack bar plot with R. I already took a look at a number of answers but some were not specific to my

3条回答
  •  情话喂你
    2021-01-06 12:56

    I'm basically answering a different question. I suppose this can be seen as perversity on my part, but I really dislike barplots of pretty much any sort. They have always seemed to create wasted space because the present informationed numerical values are less useful that an appropriately constructed table. The vcd package offers an extended mosaicplot function that seems to me to be more accurately called a "multivariate barplot that any of the ones I have seen so far. It does require that you first construct a contingency table for which the xtabs function seems a perfect fit.

    install.packages)"vcd")
    library(vcd)
    help(package=vcd,mosaic)
    col=c("paleturquoise3", "palegreen3")
    vcd::mosaic(xtabs(~Variant+Region + PrecededByPrep   +  Time, data=ttt) 
               ,highlighting="Variant", highlighting_fill=col)
    

    enter image description here

    That was the 5 way plot and this is the 5-way plot:

    png(); vcd::mosaic( xtabs(
                      ~Variant+Region + PrecededByPrep +   Person  +  Time, 
                       data=ttt) 
                    ,highlighting="Variant", highlighting_fill=col); dev.off()
    

    enter image description here

提交回复
热议问题