0
votes

I want to skip a empty panel using lattice package in R.

set.seed(1)
df1 <- data.frame("treatment" = c(rep("A",16),rep("B",16),rep("C",16)),
                  "disease_type" = c(rep("1",8),rep("2",8)),
                  "days_after_application" = rep(c(rep("10-24",4),rep("24-48",4)),6),
                  "severity" = rnorm(48, mean = 80, sd = 5))
df1[(df1$disease_type == "2" & df1$days_after_application == "24-48"),"severity"] <- NA
library(lattice)
figure1 <- bwplot(treatment~severity|days_after_application+disease_type,
                  data = df1,layout = c(2,2),
                  strip = strip.custom(strip.names = TRUE))
jpeg("figure1.jpeg")
print(figure1)
dev.off()

Here is what I get Figure1

My question is how I can remove/skip empty panel in the top right WITHOUT changing layout?

I have tried following code. However, it doesn't work.

figure2 <- bwplot(treatment~severity|days_after_application+disease_type,
                  data = df1,layout = c(2,2),
                  strip = strip.custom(strip.names = TRUE),
                  skip = c(FALSE,FALSE,FALSE,TRUE))
jpeg("figure2.jpeg")
print(figure2)
dev.off()

Here is what I got

Figure2

I also tried following codes. But it is not what I want since I do want 2 levels strips.

df1[(df1$disease_type == "2" & df1$days_after_application == "24-48"),] <- NA
bwplot(treatment~severity|interaction(days_after_application,disease_type),
       data = df1,layout = c(2,2),
       strip = strip.custom(strip.names = TRUE))

Thank you!

1

1 Answers

0
votes

Get help from a Professor in Temple University.

Here is his solution:

figure4 <- bwplot(treatment~severity|days_after_application+disease_type,
                  data = df1,layout = c(2,2),
                  strip = strip.custom(strip.names = TRUE),
                  skip = c(FALSE,FALSE,FALSE,TRUE),
                  scales=list(alternating=FALSE),  ## keep x-scale on bottom
                  between=list(x=1, y=1))          ## space between panels
pdf("figure4%03d.pdf",onefile = FALSE) ## force two pages in file.
print(figure4)
dev.off()