Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>An alternative following your original <code>text</code> expression:</p> <pre><code>par(mar=c(6, 4.1, 4.1, 2.1)) labels &lt;- paste(c("RB-GL830-[16]-10", "RB-GL830-[16]-30", "SB-GL834-[11]-10", "SB-GL834-[11]-30", "RB-GL843-[17]-10", "RB-GL843-[17]-30")) boxplot(count ~ spray, data = InsectSprays, col = "lightgray", xaxt = "n", xlab = "") # x axis with ticks but without labels axis(1, labels = FALSE) # Plot x labs at default x position text(x = seq_along(labels), y = par("usr")[3] - 1, srt = 45, adj = 1, labels = labels, xpd = TRUE) </code></pre> <p>Why use <code>x = seq_along(labels)</code> for label positions? The <code>x</code> in <code>text</code> is a vector of coordinates where to put the labels. If you look at <code>?boxplot</code>, you find that the <code>at</code> argument is a "numeric vector giving the locations where the boxplots should be drawn [...]; defaults to 1:n where n is the number of boxes." Because we haven't specified the <code>at</code> argument in the <code>boxplot</code> call, the default "1:n positions" will be used. The number of boxes is of course the number of levels of your explanatory variable, which @Josh O'Brien used in his answer. To show you an alternative, I used your customized label vector instead (which of course must have the same length as the number of factor levels). <code>seq_along</code> generates a regular sequence from 1 to <code>length</code> of the argument, which corresponds to the "defaults to 1:n" <code>at</code> positions.</p> <p>A side-note: your data seem to be in a 'wide' format. In many instances in R, it is more convenient to have the data in a 'long' format. In the <code>plot</code> function, you then only need to specify your x variable (e.g. location) and y variable (e.g. soil temp), instead of specifying data for every single level of x. <img src="https://i.stack.imgur.com/onzGE.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload