deepayan / lattice

Trellis Graphics for R
http://lattice.r-forge.r-project.org/
Other
68 stars 15 forks source link

bwplot: Cannot remove y-axis labels with scales$y$labels = NULL #26

Open stefaneng opened 1 year ago

stefaneng commented 1 year ago

y-axis labels can be removed by setting scales$y$labels = NULL in lattice::xyplot, lattice::histogram, and others but it does nothing when using lattice::bwplot.

Example:

library(lattice)
set.seed(10)
simple.data <- data.frame(
    x = rnorm(100),
    y = sample(1:5, replace = T, size = 100)
    )
# scales$y$labels = NULL removes yaxis labels for other plot types
lattice::xyplot(y ~ x, data = simple.data, scales=list(y=list(labels=NULL)))

lattice::histogram(simple.data$x, scales=list(y=list(labels=NULL)))


# Does not work to remove y-axis labels in bwplot
lattice::bwplot(y ~ x, data = simple.data, scales=list(y=list(labels=NULL)))


# Works fine to remove xaxis labels
lattice::bwplot(y ~ x, data = simple.data, scales=list(x=list(labels=NULL)))

Created on 2023-01-06 with reprex v2.0.2

m-jahn commented 1 year ago

I can confirm this. As a workaround you can use something like:

lattice::bwplot(y ~ x, data = simple.data, scales=list(y=list(labels=rep("", 5))))

But of course, that's not a fix of the inconsistent behavior.

deepayan commented 1 year ago

Well, labels=NULL is not documented to be a valid choice, so the behaviour is undefined. The reason for the inconsistency is that xyplot() and bwplot() have different "defaults" for scales.

My suggestion would be to either use

scales=list(y=list(at = numeric(0)))

(documented, but no tick marks), or

default.scales = list(y=list(labels = NULL))

(technically undefined, but likely to work for the foreseeable future).