boxplot with multiple factor labels using base R functions
<p>How can one possibly reproduce the <code>ggplot-based</code> <code>boxplot</code>  shown in this <a href="https://stackoverflow.com/questions/10441214/r-boxplot-with-multiple-factor-labels">answer</a> but using <code>base R boxplot function</code>?</p>

<p>Sample date from the above link:</p>

<pre><code>d&lt;-data.frame(x=rnorm(1500),f1=rep(seq(1:20),75),f2=rep(letters[1:3],500))
# first factor has 20+ levels
d$f1&lt;-factor(d$f1)
# second factor a,b,c
d$f2&lt;-factor(d$f2)

boxplot(x~f2*f1,data=d,col=c("red","blue","green"),frame.plot=TRUE,axes=FALSE)
</code></pre>

<p>It would be great if the groups on the <code>x-axis</code> are spaced from each other.</p>

<p>I have limited knowledge about <code>ggplot2</code>.</p>

<p><strong>EDIT</strong></p>

<p>While waiting for more suggestions using base R functions, I am making some progress with ggplot2.</p>

<p>Using this sample data how can I produce a plot with well aligned <code>x-axis</code> as the one in the link above?</p>

<p>The following does not give me the correct alignment (I want the numbers 1:8 aligned at the center of each group):</p>

<pre><code>library(ggplot2)
ggplot(dat3, aes(x = ID, y = value,  group=interaction(obs, ID), fill=obs)) +
  geom_boxplot() +
  scale_fill_manual(values = c("yellow", "orange"))


    dat3=structure(list(values = c(0, 0, 0, 0, 0, 0, 0, 0, -0.0169491525423729, 
0, 0, 0, 0, 1, 1, 0.64367816091954, 0.64367816091954, 0, 0, -0.0163934426229508, 
-0.021978021978022, 0.109195402298851, 0, 0, 0, 0, 0.207650273224044, 
0.4375, 0, 0, 0, 0, 0.302325581395349, 0.303370786516854, 0.270588235294118, 
-0.0188679245283019, 0.156462585034014, 0.092436974789916, 0.69, 
-0.021978021978022, 0.64367816091954, 0.614906832298137, 0.612903225806452, 
0.274853801169591, 0, 0.303370786516854, 0, 0, -0.03125, 0.229813664596273, 
0.557142857142857, 0, 0.109195402298851, 0.0746268656716418, 
0.180616740088106, 0.210526315789474, 0.310344827586207, 1, 1, 
0.0825688073394495, 0.294117647058824, 0, 0.4375, 0, 0.230769230769231, 
0.347826086956522, -0.0163934426229508, 0.156462585034014, 0, 
0, 0, 1, 0, 0, 0, 0.483333333333333, 0.483333333333333, 0, 0, 
0, 0, 0, -0.0169491525423729, 0, 0.310344827586207, 0, 0.296875, 
0.302325581395349, 0, 0, 0, 0, 0, 0, 0.482758620689655, 0, 0, 
0, 0, 0, 0, 0, 0, 0.150684931506849, 0.150684931506849, 0, 0, 
-0.021978021978022, -0.021978021978022, 0.270588235294118, 0, 
0, 0.482758620689655, 0.482758620689655, 0.272727272727273, 0.272727272727273, 
0, 1, 0, 0, 0.642857142857143, 0.211864406779661, 0.156462585034014, 
-0.0449438202247191, -0.0449438202247191, 0.389763779527559, 
0.389763779527559, -0.021978021978022, 0.211864406779661, 0.213197969543147, 
0.213197969543147, 0.358620689655172, -0.0163934426229508, 0.483333333333333, 
0, 0, 0.362139917695473, 0.362139917695473, 0.261904761904762, 
0.483333333333333, 1, 1, 0.236453201970443, 0.302325581395349, 
0.310344827586207, 1, 1, 0.358974358974359, 0.358974358974359, 
-0.0606060606060606, 0.0721649484536082, 0.615384615384615, 0.615384615384615, 
0.347826086956522, 1, 0, 0, 0, -0.0273972602739726, -0.0273972602739726, 
-0.0169491525423729, -0.0256410256410256, 0.107142857142857, 
0.107142857142857, 0.302325581395349, -0.0163934426229508, -0.0264900662251656, 
0.311111111111111, 0.311111111111111, 0.156462585034014, 0.156462585034014, 
-0.0483091787439614, 0.311111111111111, -0.0333333333333333, 
-0.0333333333333333, 0.311111111111111), ind = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 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"obs"), row.names = c(NA, 176L), class = "data.frame")
</code></pre>