I am new to lattice and I need to create a box plot where y value represent electric current. The data is oranized on different ratios ranging from 1/24 to 8/1. When plotting fortunately I get the relative position of the boxes to respect the actual ratios. What I am trying to achieve is to use x-labels such as "1/24", 1/12 etc. instead of "0.04166667", 0.08333333 etc. You can see an example of the code bellow. I have tried different approaching inside the panel function and also explored the scales argument. The data is conditioned and 4 panels result. The tricky bit is that the panels from right and the panels from left have different x-ranges.

The code:

bwplot(current~factor(ac.ratio)|factor(constant.electrode)+factor(substrate), data=current.df, 
       scales=list(x=list(relation="free",
                          at=c(1/24, 1/12, 1/6, 1/3, 2/3, 1, 2, 4, 8),
                          labels = FALSE), 
                   y="same"), 
       layout=c(2,2), index.cond=list(2:1, 2:1))

An example of what I obtain is: enter image description here

And what I need is something similar to: enter image description here

Also the positions in the left panels must overlap (like those from the right panels). This is what I need (The panel titles are only as examples, not final). Thank you very much.

1

There are 1 best solutions below

0
Johan Larsson On

Here is a solution using xyplot in place of bwplot and calling panel.bwplot internally. I had to manually adjust box.width to get a reasonable result.

library(lattice)

dd <- data.frame(
  current = rnorm(200, 350, 50),
  ac.ratio = sample(c(1/24, 1/12, 1/6, 1/3), 200, replace = TRUE),
  substrate = gl(2, k = 100, labels = c("Acetate", "OECD"))
)

xyplot(current ~ ac.ratio | substrate, data = dd, box.width = 0.02,
       scales = list(x = list(at = c(1/24, 1/12, 1/6, 1/3),
                              labels = c("1/24", "1/12", "1/6", "1/3"))),
       panel = panel.bwplot, horizontal = FALSE)

Imgur