1

While plotting a boxplot in R, I noticed not all values in the y-axis are presented. Possible values are -5 to 5, but actual values are -1.3 to 4.6, so the values presented on the y-axis are -2 to 5. I want it to be presented with all values: -5 to 5, even though there's no data for this entire range.

My code looks like this:

boxplot(depvar ~ indepvar, data = a, pars = list(outlwd = 2, outcex = 1.8), axes = FALSE) axis(side = 2, at = seq(-5, 5, by = 1), las = 1, tck = 7)

What should be added/changed for the y-axis to be fully-presented?

Stars
  • 25
  • 4
  • 2
    Hi Stars, welcome to Stack Overflow. It will be much easier to help if you provide at least a sample of your data with `dput(a)` or if your data is very large `dput(a[1:20,])`. You can edit your question and paste the output. You can surround it with three backticks (```) for better formatting. See [How to make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more info. – Ian Campbell Apr 29 '20 at 13:00

2 Answers2

1

Appears simliar to this question: How to set the y range in boxplot graph?

I think you are looking for ylim.

a <- c((randu$x*3)-2)

boxplot(x = a,
  ylim = c(-5,5))

enter image description here

JD Caddell
  • 383
  • 2
  • 10
0

Load Packages

install.packages("dplyr") library(dplyr)

creating random set with two columns:

set.seed(10)
 df <- dplyr::data_frame(
  x = 1:5,
  y = 1:5)

Visualize in a boxplot with expanded axis:

boxplot(x~y,
  df,
  xlim =c(-5,5),
  ylim =c(-5,5))
Boudu
  • 85
  • 7