Pabs88
Pabs88

Reputation: 43

Boxplots in R. Y interval (tick marks) and grid

I have the following code:

  boxplot(c(Scatt_nocoop, Scatt_coop), 
          xlab="Scattered", col=c("red","red"), 
          names=c("Non-cooperative"," Cooperative "), 
          ylim = c(0,2.5))

I am trying to add tick marks in the Y axis every 0.1, to then add a grid.

Also, I would like to get the Y axis in percentage rather than with numbers.

Thank you!

Upvotes: 1

Views: 3588

Answers (1)

Wietze314
Wietze314

Reputation: 6020

not sure what your data looks like, but I guess you want something like this:

x1 <- rnorm(100) + 2

x2 <- rnorm(100) + 2

df <- data.frame(x = c(x1, x2), g = rep(1:2,each=100))

boxplot(df$x~df$g, 
        xlab="Scattered", col=c("red","red"), 
        names=c("Non-cooperative"," Cooperative "), 
        ylim = c(0,5),
        yaxt = "n")

add ticks and (manual) grid lines

axis(2, at = seq(0,5,0.1))
lapply(seq(0,5,0.1), function(x) abline(a = x,b = 0))

Upvotes: 2

Related Questions