0

I have created boxplots for cell composition data for 4 sample groups, indicated by the code below and link to the plot. My question (which is probably quite basic) is how do I insert spacing on the x-axis in between each cell type so that the 4 boxes for each cell type are grouped more clearly?

par(mfrow=c(1,1))
a = cellCounts[targets$Sample_Group == "CTL",] 
b = cellCounts[targets$Sample_Group == "SRF",] 
c = cellCounts[targets$Sample_Group == "REM",] 
d = cellCounts[targets$Sample_Group == "REF",] 

boxplot(a, at=0:5*4 + 1, xlim=c(0, 25), ylim=range(a, d), xaxt="n",
    col=col.pal[1], main="", ylab="Cell type proportion")
boxplot(b, at=0:5*4 + 2, xaxt="n", add=TRUE, col=col.pal[2]) 
axis(1, at=0:5*4 + 2.5, labels=colnames(a), tick=TRUE) 
boxplot(c, at=0:5*4 + 3, xaxt="n", add=TRUE, col=col.pal[3]) 
axis(1, at=0:5*4 + 2.5, labels=colnames(a), tick=TRUE)
boxplot(d, at=0:5*4 + 4, xaxt="n", add=TRUE, col=col.pal[4]) 
axis(1, at=0:5*4 + 2.5, labels=colnames(a), tick=TRUE)

legend("topleft", legend=c("CTL","SRF","REM","REF"), fill=col.pal)

boxplot

(Code adapted from Maksimovic et al. 2016)

M--
  • 25,431
  • 8
  • 61
  • 93
Ellen
  • 1
  • 1

0 Answers0