制作分组数据的箱线图

时间:2017-12-26 04:25:34

标签: r boxplot

我有4个数据框,包含看起来像这样的数据(HuL1是骨骼):

   CEMETERY    SEX CONTEXT HuL1.L HuL1.R DIRECTIONAL.ASYMMETRY
1  Medieval FEMALE    7172    285    286             0.3508772
2  Medieval FEMALE    8117    316    320             1.2658228
3  Medieval FEMALE   11090    309    312             0.9708738
14 Medieval FEMALE      19    326    332             1.8404908
15 Medieval FEMALE     349    310    313             0.9677419
16 Medieval FEMALE     383    319    322             0.9404389

        CEMETERY  SEX CONTEXT HuL1.L HuL1.R DIRECTIONAL.ASYMMETRY
43 Post-Medieval MALE      20    317    321             1.2618297
44 Post-Medieval MALE      35    334    332            -0.5988024
45 Post-Medieval MALE      47    328    334             1.8292683
46 Post-Medieval MALE     143    332    332             0.0000000
47 Post-Medieval MALE     147    351    354             0.8547009

每个数据帧的长度不同,2由“中世纪”和“中世纪”组成。数据,而另外2个是中世纪后(A =中世纪女性数据,B =中世纪男性数据,C =中世纪后女性数据,D =中世纪后男性数据)。 我用

制作了一个箱线图
 x=boxplot(A$DIRECTIONAL.ASYMMETRY,B$DIRECTIONAL.ASYMMETRY,
C$DIRECTIONAL.ASYMMETRY
,D$DIRECTIONAL.ASYMMETRY,xlab="PERIOD",ylab="DIRECTIONAL ASYMMETRY 
(%)",names=c("Medieval","Medieval","Post-Medieval","Post-
Medieval"),col=c("turquoise","red","turquoise","red"))

legend(x="topleft",title="Sex",c("Female","Male"),fill=c("turquoise","red"))

enter image description here

但我想要中世纪的'和后中世纪的'要绘制在一起的图,所以x轴只表示中世纪和后中世纪。

1 个答案:

答案 0 :(得分:0)

boxplot(A$DIRECTIONAL.ASYMMETRY,B$DIRECTIONAL.ASYMMETRY,
        C$DIRECTIONAL.ASYMMETRY, D$DIRECTIONAL.ASYMMETRY, 
        xlab="PERIOD",ylab="DIRECTIONAL ASYMMETRY(%)",
        col=c("turquoise","red","turquoise","red"))

axis(side = 1, at = c(1.5, 3.5), labels = c("Medieval", "Post-Medieval"))

legend(x="topleft",title="Sex",c("Female","Male"),fill=c("turquoise","red"))