【问题标题】:rearranging panels in lattice xyplot重新排列格子 xyplot 中的面板
【发布时间】:2014-08-28 12:30:09
【问题描述】:

以下是我仅以单个变量为条件时使用的代码。如下使用 index.cond 来切换最终图表中面板的顺序。但是,现在我以两个变量为条件,下面的代码无法切换不同面板的位置。如何修改 index.cond 才能工作?这是我的代码,下面是图表和示例数据的图片:

libs <- c('lattice', 'latticeExtra', 'gridExtra', 'MASS', 'colorspace', 'plyr', 'Hmisc', 'scales')
lapply(libs, require, character.only = T)


conversion_test <- read.table("Desktop/FAST/convert_test/Results/fasconvert_Results", sep="\t",   header=TRUE)


scatter.lattice <- xyplot(Time.to.Completion..s. ~ Number.of.Sequences | Length * Conversion, data  = conversion_test, ylab = "Time to Completion (s)", xlab = "Number of Sequences", index.cond=list(c(2,1,4,3)), pch=16, 
                         panel = function(x, y, ...) {
                         panel.xyplot(x, y, ...)
                         lm1 <- lm(y ~ x)
                         lm1sum <- summary(lm1)
                         r2 <- lm1sum$adj.r.squared
                         panel.abline(a = lm1$coefficients[1], 
                                      b = lm1$coefficients[2])
                         panel.text(labels = 
                                      bquote(italic(R)^2 == 
                                               .(format(r2, 
                                                        digits = 5))),
                                    x = 500000, y = 10)
                         },
                       xscale.components = xscale.components.subticks,
                       yscale.components = yscale.components.subticks,
                       as.table = TRUE)
scatter.lattice

我想切换列的顺序。

这是一个示例数据集:

Numberofseq timetoCompletion Length Conversion
25000         9.3             100bp    ClustalW
250000        45              100bp    ClustalW
25000         9.3             100bp    Fasta
250000        45              100bp    Fasta
25000         9.3             1000bp    ClustalW
250000        45              1000bp    ClustalW
25000         9.3             1000bp    Fasta
250000        45              1000bp    Fasta  

【问题讨论】:

  • 切换顺序到底如何?期望的输出是什么?
  • 我想切换列的顺序。为了更明确地从左到右编号,上图从上到下我希望顺序是 2,1,4,3。

标签: r panel lattice


【解决方案1】:

来自?xyplot 帮助页面,在index.cond 下,

如果 index.cond 是一个列表,它必须与条件变量的数量一样长,并且第 i 个组件必须是级别 (g_i) 的有效索引向量,其中 g_i 是第 i 个图中的条件变量

既然你有两个条件变量,你应该有一个长度为 2 的列表。您的每个变量都有两个级别。我仍然不明白你是如何对这些地块进行编号的,但是根据你的因素是如何平衡的,尝试某种形式的

index.cond = list(2:1, 2:1)
#or
index.cond = list(2:1, 1:2)

但将它与as.table 一起使用似乎有点奇怪。

【讨论】:

  • 我现在正在学习 R 来创建用于发布的绘图,因为我主要是在复制代码。我将删除 as.table。
  • 点阵显示中的默认布局从下往上计算行数。要从上到下显示,请使用 lattice.options(default.args = list(as.table = TRUE))
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-06
  • 2019-05-29
  • 2019-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-01
相关资源
最近更新 更多