I am generating a plot with xyplot from the lattice package. I use the following command:

xyplot(Y ~ X | Bench, dt, type = 'o')

And this is the result:

sample image

On the Y axis there is a tick without label (0.85). Is there any way to force lattice to print a label next to the tick (as it does for all the others: 1.00, 0.95 and 0.90)?

EDIT: I'm aware of some "manual" ways to tweak a plot in such a way that all the ticks have a corresponding label. But the methods I know of depend on the actual data being plotted, and they may require adjustments if the data changes. I'm looking for an automatic solution to this. Like some sort of flag that instructs xyplot not to leave a tick without its associated label. Of course, it might just happen such a flag does not exist... Knowing that would be helpful too.

有帮助吗?

解决方案

You can specify axis tick locations explicitly using the scales= argument, which skips the automatic axis label clipping:

xyplot(..., scales=list(y=list(at=seq(.85, 1, .05)), x=list(at=...)))

EDIT: Here you go, more automated:

axis.overlap <- function(..., components) {
  components$bottom$labels$check.overlap <- FALSE
  axis.default(..., components=components)
}

Then anytime you want to include axis-overlapping labels, you can specify:

xyplot(Y ~ X | Bench, dt, axis=axis.overlap)

or wrap it as you please:

xyplot2 <- function(..., axis=axis.overlap) xyplot(..., axis=axis)

xyplot2(Y ~ X | Bench, dt)

其他提示

scales=list(alternating=3) should do the trick.

See https://www.rdocumentation.org/packages/lattice/versions/0.20-41/topics/B_00_xyplot for other possible values of alternating

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top