简体   繁体   中英

Making boxplot of grouped data

I have 4 data frames consisting of data that looks like this (HuL1 is a bone):

   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

and

        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

Each dataframe is a different length, and 2 consist of 'Medieval' data whilst the other 2 are 'Post-Medieval (A = medieval female data, B= medieval male data, C = post-medieval female data, D = post-medieval male data). I have made a boxplot using

 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"))

在此处输入图片说明

but I want the 'Medieval' and 'Post-Medieval' plots to be grouped together, so the x-axis only says Medieval and Post-Medieval once.

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM