Stars
Stars

Reputation: 35

How to force the presentation of all y-axis value in R?

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?

Upvotes: 1

Views: 642

Answers (2)

Boudu
Boudu

Reputation: 87

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))

Upvotes: 0

JD Caddell
JD Caddell

Reputation: 403

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

Upvotes: 1

Related Questions