I would like to plot box plots for a data set that including four categorical such as: Good, Bad, VeryGood, and VeryBad and four normal distribution. My question how to make plots the four categorical with four different normal distribution in one plot separate from each other, I have tried (see below) but there look a mess. I have used an example that I found it here and did some changes on it. I added another edited plot which I would like each plot of box plot look like this one which more cleat and each four categorical (blue, yellow, red and green) are clear .
par(mfrow=c(2,2))
df <- data.frame(id = c(rep("Good",200), rep("Bad", 200),
rep("VeryGood",200), rep("VeryBad",200)),
F1 = c(rnorm(200,10,2), rnorm(200,8,1), rnorm(200,5,2),rnorm(200,7,3)),
F2 = c(rnorm(200,7,1), rnorm(200,6,1), rnorm(200,8,1),rnorm(200,12,4)),
F3 = c(rnorm(200,6,2), rnorm(200,9,3),rnorm(200,12,3),rnorm(200,15,2)),
F4 = c(rnorm(200,12,3), rnorm(200,8,2),rnorm(200,8,5),rnorm(200,5,1)))
boxplot(df[,-1], xlim = c(0.5, ncol(df[,-1])+0.9),
boxfill=rgb(1, 1, 1, alpha=1), border=rgb(1, 1, 1, alpha=1)) #invisible boxes
boxplot(df[which(df$id=="Good"), -1], xaxt = "n", add = TRUE, boxfill="red", boxwex=0.25,
at = 1:ncol(df[,-1]) - 0.15) #shift these left by -0.15
boxplot(df[which(df$id=="Bad"), -1], xaxt = "n", add = TRUE, boxfill="blue", boxwex=0.25,
at = 1:ncol(df[,-1]) + 0.15) #shift these right by +0.15
boxplot(df[which(df$id=="VeryBad"), -1], xaxt = "n", add = TRUE, boxfill="green", boxwex=0.25,
at = 1:ncol(df[,-1]) + 0.25) #shift these right by +0.15
boxplot(df[which(df$id=="VeryGood"), -1], xaxt = "n", add = TRUE, boxfill="yellow", boxwex=0.25,
at = 1:ncol(df[,-1]) + 0.45) #shift these right by +0.15
par(mfrow=c(2,2))
? – G5Wpar(mfrow=c(2,2))
. Is that correct? – G5W