R 网格图中的完整标签

发布于 2024-11-14 10:34:19 字数 549 浏览 3 评论 0原文

我在 R 中的网格图上获取标签时遇到一些问题。这是下面的一个示例,

x <- c(1,2,3)
y <- c(2,4,6)
z <- c(0.1,0.5,2)
combo <- expand.grid(x,y,z)
combo <- data.frame(combo)
names(combo) <- c("x","y","z")
outcome <- function(l){
    (l[1]*l[2]) / l[3]
}

resp <- apply(combo, 1, outcome)

levelplot(resp ~ x * y | z, data = combo, pretty = TRUE, region = TRUE, 
          contour = FALSE)

我理想情况下希望每个标签都标记为“z=0.1”、“z=0.5”和“z=2”。我可以让它说出 z (就像现在一样),并让它说出没有 z 的值,但我真的想要两者。有人可以帮忙吗?

谢谢。

PS(对代码上的间距表示歉意,格式似乎有点混乱!)

I'm having some trouble getting labels on a trellis plot in R. This is an example below

x <- c(1,2,3)
y <- c(2,4,6)
z <- c(0.1,0.5,2)
combo <- expand.grid(x,y,z)
combo <- data.frame(combo)
names(combo) <- c("x","y","z")
outcome <- function(l){
    (l[1]*l[2]) / l[3]
}

resp <- apply(combo, 1, outcome)

levelplot(resp ~ x * y | z, data = combo, pretty = TRUE, region = TRUE, 
          contour = FALSE)

I ideally want each one to be labeled "z=0.1" "z=0.5" and "z=2". I can get it to say z ( as it does currently), and get it to say the value without z, but I really want both. Can anyone help?

Thanks.

P.S (apologies for spacing on the code, formatting seems to have messed it up a bit!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光飞翔i 2024-11-21 10:34:19

使用您想要作为标签的文本将 z 设为因子。这里我创建了一个新变量 zF 作为 z 的因子,以保持原始 z 不变。我还以我喜欢的方式重写了您的数据生成命令;也许你会发现这也很有用。

zz <- c(0.1, 0.5, 2)
combo <- expand.grid( x = c(1, 2, 3),
                      y = c(2, 4, 6),
                      z = zz )
combo$resp <- with(combo, x*y/z)
combo$zF <- with(combo, factor(z, levels=zz, labels=paste("z =", zz)))

levelplot(resp ~ x * y | zF, data = combo, pretty = TRUE, region = TRUE, 
          contour = FALSE)

Make z a factor with the text you want as the labels. Here I make a new variable zF as a factor of z to leave the original z unchanged. I also rewrote your data generation commands in a way I prefer; perhaps you will find that useful too.

zz <- c(0.1, 0.5, 2)
combo <- expand.grid( x = c(1, 2, 3),
                      y = c(2, 4, 6),
                      z = zz )
combo$resp <- with(combo, x*y/z)
combo$zF <- with(combo, factor(z, levels=zz, labels=paste("z =", zz)))

levelplot(resp ~ x * y | zF, data = combo, pretty = TRUE, region = TRUE, 
          contour = FALSE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文