Search code examples
rstripchart

Re-arrange stripchart x-axis


This is my graph code, it's supposed to be high, medium, low but at the moment its high, low medium. Is there anything I can add to this to make it this way?

stripchart(data$Rel.abun.Chaemae ~ data$Shore.Position, 
           vertical = TRUE, 
           method = "jitter", 
           pch  = 21, 
           xlab = "Location",
           ylab = "Relative abundance (Chaemaesipho columna)", 
           ylim = c(0,1))

Solution

  • Ensure that Shore.Position is a factor. If not, set it as factor.

    str(data$Shore.Position)
    data$Shore.Position <- factor(data$Shore.Position)
    

    Then, change the order of levels as below and plot.

    data$Shore.Position <- factor(data$Shore.Position, levels = c("high", "medium", "low"))