[R] Help reproducing this boxplot

Ryan Treacy rtreacy87 at gmail.com
Thu Oct 13 18:48:42 CEST 2016


I am trying to reproduce the style of boxplot pictured in the attached
image.  The code below is close but I cannot get the control values the
correct color.

library(ggplot2)

box.print <- function(C1M,C1, D2, QCDC2, QCSDT4, num){
  NAME <- names(D2[num])
  adjsdt4 <- C1M[,num]
  sdt4 <- C1[,num]
  disco2 <- D2[,num]
  qcdc <- QCDC2[,num]
  qcsdt4 <- QCSDT4[,num]
  adj <- data.frame(Intensity=c(adjsdt4,qcsdt4),
                    Study= rep("adjSDT4",length(adjsdt4)+length(qcsdt4)),
                    QC=
c(rep("cases",length(adjsdt4)),rep("QC",length(qcsdt4)))

  )
  nadj <- data.frame(Intensity=c(sdt4,qcsdt4),
                     Study= rep("SDT4",length(sdt4)+length(qcsdt4)),
                     QC=
c(rep("cases",length(sdt4)),rep("QC",length(qcsdt4)))

  )
  disco <- data.frame(Intensity=c(disco2,qcdc),
                      Study= rep("DISCO2",length(disco2)+length(qcdc)),
                      QC=
c(rep("cases",length(disco2)),rep("QC",length(qcdc)))

  )
  full <- rbind(adj,nadj,disco)

  g1 <- ggplot(full, aes(x=Study, y=Intensity))+geom_boxplot(outlier.shape
= NA)+ggtitle(NAME)+
    geom_jitter(alpha=0.5, aes(color=Study,label=Study,shape=QC),position =
position_jitter(width = .8),size=2)
  g1 = g1+theme(panel.grid.major= element_blank(),
                panel.grid.minor= element_blank(),
                panel.background= element_blank(),
                panel.border= element_rect(colour="black",fill=NA),
                legend.position="none")
  g1= g1+scale_shape_manual(values=c(19,1))+scale_fill_discrete(guide=FALSE)
  print(g1)
}

A <- data.frame(1.557, 1.663, 1.637, 1.740, 1.597, 1.473, 1.399 ,1.403,
1.210, 1.375, 1.387, 1.515, 1.456,
  1.121, 1.211, 1.165, 1.428, 1.749, 1.231, 1.209, 1.272, 1.580, 1.254,
1.099, 1.151, 1.239,
  1.753, 1.415, 1.653, 1.555, 1.748, 1.951, 1.734, 1.519, 1.397, 1.391,
1.825, 1.722, 1.715,
  1.777, 2.014, 1.676, 1.803, 1.332, 1.560, 1.605, 1.564, 1.588, 1.583,
1.701, 1.297, 1.583,
  1.778, 1.343, 1.427, 1.472, 1.663, 1.472, 1.726, 1.327, 1.466, 1.890,
1.601, 1.474, 1.671,
  1.492, 1.277, 1.524, 1.394, 1.477, 1.525, 1.502, 1.371, 1.479, 0.966,
1.239, 1.415, 1.316,
  1.336, 1.244, 2.040, 1.823, 1.853, 1.712, 1.805, 1.593, 1.630, 1.578,
1.648, 1.581, 1.661,
  1.731, 1.360, 1.572, 1.788, 1.668, 1.663, 1.519)
A <- t(A)
B <- A*.3
C <- A*2
QA <- data.frame(1.951, 1.734, 1.519, 1.397, 1.391, 1.825)
QA <- t(QA)
QC <- QA*1.5

box.print(A,B,C,QA,QC,1)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: goal.png
Type: image/png
Size: 40893 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161013/0eb5abd9/attachment.png>


More information about the R-help mailing list