【问题标题】:Skip empty panel using lattice package, R programming使用格子包跳过空面板,R编程
【发布时间】:2018-04-19 17:35:55
【问题描述】:

我想在 R 中使用 lattice 包跳过一个空面板。

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()

这是我得到的

我的问题是如何在不改变布局的情况下删除/跳过右上角的空白面板?

我尝试了以下代码。但是,它不起作用。

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()

这是我得到的

我还尝试了以下代码。但这不是我想要的,因为我确实想要 2 个级别的条带。

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))

谢谢!

【问题讨论】:

    标签: r panel lattice


    【解决方案1】:

    向坦普尔大学教授寻求帮助。

    这是他的解决方案:

    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()
    

    【讨论】:

      猜你喜欢
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多