barplot x-axis labels with hierarchical grouping variables in separate rows

后端 未结 1 877
名媛妹妹
名媛妹妹 2020-12-21 00:18

In Excel, with data organized like so:

                                              Bare NP                   Singular-Marked NP               Plural-Marked         


        
相关标签:
1条回答
  • 2020-12-21 01:08

    A bit of manual adjustment of the margins and calling axis() twice can get you there. Saving a barplot like bp <- barplot(...) saves the midpoints of each bar for future reference.

    oldpar <-par(mar=c(7,5.1,4.1,2.1))
    
    bp <- barplot(a,
            col=c("blue","red","purple"),
            ylab="Frequency of Interpretation",
            xlab="",
            main="Frequency of BrP and AmE Interpretations \n of NPs in Neutral Environments",
            axisnames=FALSE
           )
    

    You can then use the values stored in bp to align things properly. You can align the group and sub-group labels using the line=... argument to axis()

    avgpts <- tapply(bp,rep(1:3,each=2),mean)
    grps <- c("Bare NP","Singular-Marked NP","Plural-Marked NP")
    subgrps <- c("BrP","AmE")
    axis(1,at=bp,labels=rep(subgrps,3), cex.axis=0.7)
    axis(1,at=avgpts,labels=grps, cex.axis=0.7,line=1.5,lwd=0)
    
    title(xlab="Form of NP and Native Language",line=4.5)
    

    Resulting in:

    enter image description here

    0 讨论(0)
提交回复
热议问题