R lattice 3d plot: ticks disappear when changing p

2019-07-07 02:32发布

问题:

The following code using cloud produces a plot with tick marks as expected:

require(lattice)
cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris,
scales = list(arrows=F))

When the panel border thickness is changed using axis.line within the par.setting argument, the border thickness gets changed but the tick marks disappear, whether or not the tck argument is invoked within scales:

cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris,
scales = list(arrows=F, tck=1),
par.settings = list(
axis.line = list(lwd = 0.5)))

This seems to happen with other 3d functions, such as wireframe. Is there something I overlooked, and how could I fix this? Thank you very much for your help.

回答1:

I think it's a bug in the code. If you change the distance argument to make tickmarks longer and then also try to make the ticks thicker, it results in a different line type rather than thicker ticks:

cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris,
       scales = list(arrows=F, distance=c(2), draw = TRUE),
       par.settings = list(axis.line = list(lwd = 3)) # Dashed lines instead of thicker
       )

So there seems to be some "cross talk" on the par-channels. Furthermore, if you use the lty parameter, you get the desired changes in tick width:

cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris,
      scales = list(arrows=F, distance=c(2), draw = TRUE),
      par.settings = list(axis.line = list(lty = 0.5))   # Success
      )

I'm guessing this also affects the wireframe function, since they are at their core very similar, just with different panel functions. (This is on Mac's running R 2.15.3 and lattice 0.20-15 as well as in R 3.0.2 / lattice 0.20-24.)



回答2:

The reason the ticks seem to disappear is because lattice is basing their thickness upon the axis.line argument.

cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris,
      scales = list(arrows=F, tck=c(3), draw = TRUE),
      par.settings = list(axis.line = list(lwd = 0.5))
      )

In the above example, I changed the tck argument to 3, but kept your lwd argument at 0.5 You can see that R has pushed out the tick labels - so they are still being rendered but appear invisible.

Now, if you run:

cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris,
      scales = list(arrows=F, tck=c(3), draw = TRUE),
      par.settings = list(axis.line = list(lwd = 2))
      )

You see that the ticks are still there, but are being drawn in a ratio to the axis.line argument, so really - the next question is: what are you actually trying to accomplish with passing axis.line = list(lwd = 0.5)?