p3rand0r p3rand0r - 1 month ago 13
R Question

How to put 2 boxplot in one graph in R without additional libraries?

I have this kind of dataset

Defect.found Treatment Program

1 Testing Counter
1 Testing Correlation
0 Inspection Counter
3 Testing Correlation
2 Inspection Counter


I would like to create two boxplotes, one boxplot of detected defects per program and one boxplot of detected defects per technique but in one graph.

Meaning having:

boxplot(exp$Defect.found ~ exp$Treatment)
boxplot(exp$Defect.found ~ exp$Program)


In a joined graph.

Searching on Stackoverflow I was able to create it but with lattice library typing:

bwplot(exp$Treatment + exp$Program ~ exp$Defects.detected)


but i would like to know if its possible to create the graph without additional libraries like
ggplot
and
lattice

Answer

Prepare the plot window to receive two plots in one row and two columns (default is obviously one row and one column):

par(mfrow = c(1, 2))

My suggestion is to avoid using the word exp, because it is already used for the exponential function. Use for instance mydata.

Defects found against treatment (frame = F suppresses the external box):

with(mydata, plot(Defect.found ~ Treatment, frame = F))

Defects found against program (ylab = NA suppresses the y label because it is already shown in the previous plot):

with(mydata, plot(Defect.found ~ Program, frame = F, ylab = NA))