更改格子图中条带上的文本

发布于 2024-12-03 16:22:14 字数 660 浏览 1 评论 0原文

如何更改格子图中显示的文本? 例子: 假设我有一个由 3 列组成的数据框测试,

x
 [1]  1  2  3  4  5  6  7  8  9 10

y
 [1] "A" "A" "A" "A" "A" "B" "B" "B" "B" "B"

a
 [1] -1.9952066 -1.7292978 -0.8789127 -0.1322849 -0.1046782  0.4872866
 [7]  0.5199228  0.5626998  0.6392686  1.6604549

对格子图的正常调用

xyplot(a~x | y,data=test)

将在条带上显示带有文本“A”和“B”的图,

如何在条带上写入不同的文本?

尝试使用另一个字符向量

z
 [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "b"

并调用 strip.custom()

xyplot(a~x | y,data=test,strip=strip.custom(var.name=z))

不会给出所需的结果。

实际上这是一个国际化问题。

how do I change the text displayed in the strips of lattice plots?
example:
suppose I have a data frame test consisting of 3 columns

x
 [1]  1  2  3  4  5  6  7  8  9 10

y
 [1] "A" "A" "A" "A" "A" "B" "B" "B" "B" "B"

a
 [1] -1.9952066 -1.7292978 -0.8789127 -0.1322849 -0.1046782  0.4872866
 [7]  0.5199228  0.5626998  0.6392686  1.6604549

a normal call to a lattice plot

xyplot(a~x | y,data=test)

will give the plot with the Text 'A' and 'B' on the strips

How can I get different texts written on the strips?

An attept with another character vector

z
 [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "b"

and a call to strip.custom()

xyplot(a~x | y,data=test,strip=strip.custom(var.name=z))

does not give the desired result.

In reality it is an internationalization problem.

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

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

发布评论

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

评论(3

一袭白衣梦中忆 2024-12-10 16:22:14

我认为你想要的可以通过以下方式获得:

z <-c( "a" , "b" ) # Same number of values as there are panels
xyplot(a~x | y,data=test,strip=strip.custom(factor.levels=z))

I think what you want can be obtained by:

z <-c( "a" , "b" ) # Same number of values as there are panels
xyplot(a~x | y,data=test,strip=strip.custom(factor.levels=z))
╰◇生如夏花灿烂 2024-12-10 16:22:14

如果您将字符向量作为一个因素,那么您只需更改级别即可:

> xyplot(a~x | y,data=test)       # your plot
> test$y=as.factor(test$y)        # convert y to factor
> xyplot(a~x | y,data=test)       # should be identical
> levels(test$y)=c("Argh","Boo")  # change the level labels
> xyplot(a~x | y,data=test)       # new panel labels!

If you make your character vector a factor then you can just change the levels:

> xyplot(a~x | y,data=test)       # your plot
> test$y=as.factor(test$y)        # convert y to factor
> xyplot(a~x | y,data=test)       # should be identical
> levels(test$y)=c("Argh","Boo")  # change the level labels
> xyplot(a~x | y,data=test)       # new panel labels!
孤云独去闲 2024-12-10 16:22:14

这是一个老问题,但我最近因为带状疱疹和因素而苦苦挣扎。以下是使用地震数据集的两种情况的示例。

library(lattice)
data(quakes)

作为带状疱疹,使用 strip = strip.custom(strip.names=FALSE, strip.levels=TRUE) 仅显示垃圾箱。使用 as.table = TRUE 对面板进行渐进排序。使用木瓦可将色条保留在条带中。

depth1 <- equal.count(quakes$depth, number = 8, overlap = 0)

xyplot(lat ~ long | depth1, 
       data = quakes,
       xlab = "Longtitude",
       ylab = "Latitude",
       aspect = 1,
       pch = 1,
       as.table = TRUE,
       strip = strip.custom(strip.names=FALSE, strip.levels=TRUE),
       )

输入图片此处描述

作为一个因素,条带名称是自动的。

depth2 <- cut(quakes$depth, breaks=8)

xyplot(lat ~ long | depth2, 
       data = quakes,
       xlab = "Longtitude",
       ylab = "Latitude",
       aspect = 1,
       pch = 1,
       as.table = TRUE,
       )

输入图片此处描述

This is an old question, but I recently was struggling with this for shingles and factors. Here is an example for both cases using the quakes dataset.

library(lattice)
data(quakes)

As shingles, use strip = strip.custom(strip.names=FALSE, strip.levels=TRUE) to just show the bins. Use as.table = TRUE to sort the panels progressively. Using shingles retains the color bar in the strip.

depth1 <- equal.count(quakes$depth, number = 8, overlap = 0)

xyplot(lat ~ long | depth1, 
       data = quakes,
       xlab = "Longtitude",
       ylab = "Latitude",
       aspect = 1,
       pch = 1,
       as.table = TRUE,
       strip = strip.custom(strip.names=FALSE, strip.levels=TRUE),
       )

enter image description here

As a factor, the strip name automatic.

depth2 <- cut(quakes$depth, breaks=8)

xyplot(lat ~ long | depth2, 
       data = quakes,
       xlab = "Longtitude",
       ylab = "Latitude",
       aspect = 1,
       pch = 1,
       as.table = TRUE,
       )

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文