簡體   English   中英

barplot x軸標簽,在不同的行中具有分層分組變量

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

在Excel中,數據組織如下:

                                              Bare NP                   Singular-Marked NP               Plural-Marked NP   
                                    BrP Speakers    AmE Speakers    BrP Speakers    AmE Speakers    BrP Speakers AmE Speakers
Plural Interpretation               0.005747126 0.006896552         0.194117647 0.124567474         0.872093023 0.985815603
Plural & Singular Interpretation    0.649425287 0.910344828         0.029411765 0.051903114         0.127906977 0.014184397
Singular Interpretation             0.344827586 0.082758621         0.776470588 0.823529412         0           0

我能夠生成一個如下所示的堆疊條形圖:

在此輸入圖像描述

有一種簡單的方式重現方式使得x軸被划分為單獨的條件( ,“裸NP”,“奇異標記NP”及“多元標記NP”),使用R

我現在能想到的就是:

pluralInterp <- c(0.005747126,0.006896552,0.194117647,0.124567474,0.872093023,0.985815603)

pluralAndSingInterp <- c(0.649425287,0.910344828,0.029411765,0.051903114,0.127906977,0.014184397)

singInterp <- c(0.344827586,0.082758621,0.776470588,0.823529412,0,0)

a  <- rbind(pluralInterp,pluralAndSingInterp,singInterp)

colnames(a) <- c("Bare NP ~ BrP Speakers",
                 "Bare NP ~ AmE Speakers",
                 "Singular-Marked NP ~ BrP Speakers",
                 "Singular-Marked NP ~ AmE Speakers",
                 "Plural-Marked NP ~ BrP Speakers",
                 "Plural-Marked NP ~ AmE Speakers"
                 )

barplot(a,
        col=c("blue","red","purple"),
        ylab="Frequency of Interpretation",
        xlab="Form of NP and Native Language",
        main="Frequency of BrP and AmE Interpretations of NPs in Neutral Environments"
        )

其中生成以下圖表:

在此輸入圖像描述

稍微手動調整邊距並調用axis()兩次就可以實現。 保存像bp <- barplot(...)這樣的條形圖可以保存每個條形的中點以供將來參考。

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
       )

然后,您可以使用存儲在bp的值來正確對齊事物。 可以使用對准組和子組的標簽line=...參數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)

導致:

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM