R 网格图中的完整标签
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您想要作为标签的文本将
z
设为因子。这里我创建了一个新变量zF
作为z
的因子,以保持原始z
不变。我还以我喜欢的方式重写了您的数据生成命令;也许你会发现这也很有用。Make
z
a factor with the text you want as the labels. Here I make a new variablezF
as a factor ofz
to leave the originalz
unchanged. I also rewrote your data generation commands in a way I prefer; perhaps you will find that useful too.