gpt4 book ai didi

r - 如何在 Lattice 中更改绘图字符

转载 作者:行者123 更新时间:2023-12-01 06:26:37 24 4
gpt4 key购买 nike

我正在尝试使用以下数据更改 xyplot 中 lattice 使用的字符类型

> rate
Temp Rep Ind Week Weight Rate
1 9 1 B 1 2.6713 0.254
2 9 1 B 2 2.6713 0.076
3 9 1 B 6 2.6713 0.000
4 9 1 B 8 2.6713 0.000
5 9 1 MST 1 1.0154 0.711
6 9 1 MST 2 1.0154 0.137
7 9 1 MST 6 1.0154 0.000
8 9 1 MST 8 1.0154 0.000
9 9 1 MSCT 1 1.2829 0.447
10 9 1 MSCT 2 1.2829 0.345
11 9 1 MSCT 6 1.2829 0.000
12 9 1 MSCT 8 1.2829 0.000
13 9 1 MBT 1 1.8709 0.211
14 9 1 MBT 2 1.8709 0.255
15 9 1 MBT 6 1.8709 0.000
16 9 1 MBT 8 1.8709 0.000
17 9 1 MBCT 1 2.1388 0.230
18 9 1 MBCT 2 2.1388 0.281
19 9 1 MBCT 6 2.1388 0.000
20 9 1 MBCT 8 2.1388 0.000
21 9 2 S 1 0.8779 0.287
22 9 2 S 2 0.8779 0.065
23 9 2 S 6 0.8779 0.000
24 9 2 S 8 0.8779 0.000
25 9 2 MST 1 0.7196 0.197
26 9 2 MST 2 0.7196 0.193
27 9 2 MST 6 0.7196 0.000
28 9 2 MST 8 0.7196 0.000
29 9 2 MSCT 1 1.4773 0.198
30 9 2 MSCT 2 1.4773 0.233
31 9 2 MSCT 6 1.4773 0.000
32 9 2 MSCT 8 1.4773 0.000
33 9 2 MBT 1 3.4376 0.244
34 9 2 MBT 2 3.4376 0.123
35 9 2 MBT 6 3.4376 0.000
36 9 2 MBT 8 3.4376 0.000
37 9 2 MBCT 1 1.2977 0.514
38 9 2 MBCT 2 1.2977 0.118
39 9 2 MBCT 6 1.2977 0.000
40 9 2 MBCT 8 1.2977 0.000
41 12 1 B 1 3.8078 0.262
42 12 1 B 2 3.8078 0.328
43 12 1 B 6 3.8078 0.000
44 12 1 B 8 3.8078 0.000
45 12 1 MST 1 1.6222 0.294
46 12 1 MST 2 1.6222 0.213
47 12 1 MST 6 1.6222 0.000
48 12 1 MST 8 1.6222 0.000
49 12 1 MSCT 1 1.0231 0.358
50 12 1 MSCT 2 1.0231 0.281
51 12 1 MSCT 6 1.0231 0.000
52 12 1 MSCT 8 1.0231 0.000
53 12 1 MBT 1 1.2747 0.353
54 12 1 MBT 2 1.2747 0.254
55 12 1 MBT 6 1.2747 0.000
56 12 1 MBT 8 1.2747 0.000
57 12 1 MBCT 1 1.0602 0.390
58 12 1 MBCT 2 1.0602 0.321
59 12 1 MBCT 6 1.0602 0.000
60 12 1 MBCT 8 1.0602 0.000
61 12 2 S 1 0.2584 0.733
62 12 2 S 2 0.2584 0.444
63 12 2 S 6 0.2584 0.000
64 12 2 S 8 0.2584 0.000
65 12 2 MST 1 0.6781 0.314
66 12 2 MST 2 0.6781 0.421
67 12 2 MST 6 0.6781 0.000
68 12 2 MST 8 0.6781 0.000
69 12 2 MSCT 1 0.7488 0.845
70 12 2 MSCT 2 0.7488 0.661
71 12 2 MSCT 6 0.7488 0.000
72 12 2 MSCT 8 0.7488 0.000
73 12 2 MBT 1 1.1220 0.184
74 12 2 MBT 2 1.1220 0.305
75 12 2 MBT 6 1.1220 0.000
76 12 2 MBT 8 1.1220 0.000
77 12 2 MBCT 1 1.4029 0.338
78 12 2 MBCT 2 1.4029 0.410
79 12 2 MBCT 6 1.4029 0.000
80 12 2 MBCT 8 1.4029 0.000
81 15 1 B 1 3.7202 0.340
82 15 1 B 2 3.7202 0.566
83 15 1 B 6 3.7202 0.000
84 15 1 B 8 3.7202 0.000
85 15 1 MST 1 0.7914 0.668
86 15 1 MST 2 0.7914 0.903
87 15 1 MST 6 0.7914 0.000
88 15 1 MST 8 0.7914 0.000
89 15 1 MSCT 1 1.2503 0.266
90 15 1 MSCT 2 1.2503 0.402
91 15 1 MSCT 6 1.2503 0.000
92 15 1 MSCT 8 1.2503 0.000
93 15 1 MBT 1 0.7691 0.362
94 15 1 MBT 2 0.7691 0.850
95 15 1 MBT 6 0.7691 0.000
96 15 1 MBT 8 0.7691 0.000
97 15 1 MBCT 1 1.7025 0.232
98 15 1 MBCT 2 1.7025 0.462
99 15 1 MBCT 6 1.7025 0.000
100 15 1 MBCT 8 1.7025 0.000
101 15 2 S 1 0.6142 0.084
102 15 2 S 2 0.6142 0.060
103 15 2 S 6 0.6142 0.000
104 15 2 S 8 0.6142 0.000
105 15 2 MST 1 1.0184 0.318
106 15 2 MST 2 1.0184 0.638
107 15 2 MST 6 1.0184 0.000
108 15 2 MST 8 1.0184 0.000
109 15 2 MSCT 1 1.0176 0.177
110 15 2 MSCT 2 1.0176 0.343
111 15 2 MSCT 6 1.0176 0.000
112 15 2 MSCT 8 1.0176 0.000
113 15 2 MBT 1 1.6684 0.311
114 15 2 MBT 2 1.6684 0.461
115 15 2 MBT 6 1.6684 0.000
116 15 2 MBT 8 1.6684 0.000
117 15 2 MBCT 1 2.1278 0.201
118 15 2 MBCT 2 2.1278 0.489
119 15 2 MBCT 6 2.1278 0.000
120 15 2 MBCT 8 2.1278 0.000
121 18 1 B 1 3.0669 0.233
122 18 1 B 2 3.0669 0.482
123 18 1 B 6 3.0669 0.000
124 18 1 B 8 3.0669 0.000
125 18 1 MST 1 1.1641 0.208
126 18 1 MST 2 1.1641 0.201
127 18 1 MST 6 1.1641 0.000
128 18 1 MST 8 1.1641 0.000
129 18 1 MSCT 1 1.0183 0.108
130 18 1 MSCT 2 1.0183 0.303
131 18 1 MSCT 6 1.0183 0.000
132 18 1 MSCT 8 1.0183 0.000
133 18 1 MBT 1 1.2028 -0.041
134 18 1 MBT 2 1.2028 -0.004
135 18 1 MBT 6 1.2028 0.000
136 18 1 MBT 8 1.2028 0.000
137 18 1 MBCT 1 1.6395 0.072
138 18 1 MBCT 2 1.6395 0.234
139 18 1 MBCT 6 1.6395 0.000
140 18 1 MBCT 8 1.6395 0.000
141 18 2 S 1 0.5858 0.466
142 18 2 S 2 0.5858 0.336
143 18 2 S 6 0.5858 0.000
144 18 2 S 8 0.5858 0.000
145 18 2 MST 1 1.5694 0.272
146 18 2 MST 2 1.5694 0.257
147 18 2 MST 6 1.5694 0.000
148 18 2 MST 8 1.5694 0.000
149 18 2 MSCT 1 1.1295 0.523
150 18 2 MSCT 2 1.1295 0.521
151 18 2 MSCT 6 1.1295 0.000
152 18 2 MSCT 8 1.1295 0.000
153 18 2 MBT 1 1.7526 0.105
154 18 2 MBT 2 1.7526 0.118
155 18 2 MBT 6 1.7526 0.000
156 18 2 MBT 8 1.7526 0.000
157 18 2 MBCT 1 1.6924 0.320
158 18 2 MBCT 2 1.6924 0.387
159 18 2 MBCT 6 1.6924 0.000
160 18 2 MBCT 8 1.6924 0.000

绘图的代码是

rate$Temp <- as.character(rate$Temp)
rate$Week <- as.character(rate$Week)
rate$Rep <- as.character(rate$Rep)
xyplot(Rate~Weight|Rep+Temp, groups=Week, rate,auto.key=list(columns=2), as.table=TRUE, xlab="Weight (gr)", ylab="Rate (umol/L*gr)", main="All individuals and Treatments at all times")

但这给了我所有符号作为 O,我需要用不同的符号绘制每个集合。

最佳答案

我喜欢用主题机制来做这件事。黑白主题,默认会做不同的符号;你得到它是这样的:

bwtheme <- standard.theme("pdf", color=FALSE)

或者你也可以从颜色主题入手,随意修改点,如下。

mytheme <- standard.theme("pdf")
mytheme$superpose.symbol$pch <- c(15,16,17,3)
mytheme$superpose.symbol$col <- c("blue","red","green","purple")
p4 <- xyplot(Rate~Weight|Rep+Temp, groups=Week, data=rate,
as.table=TRUE,
xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
main="All individuals and Treatments at all times",
strip=strip.custom(strip.names=1),
par.settings=mytheme,
auto.key=list(title="Week", cex.title=1, space="right")
)

或者,如果您希望所有内容都在一行中,只需将您想要更改的内容传递给 par.settings

xyplot(Rate~Weight|Rep+Temp, groups=Week, data=rate,
as.table=TRUE,
xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
main="All individuals and Treatments at all times",
strip=strip.custom(strip.names=1),
par.settings=list(superpose.symbol=list(
pch=c(15,16,17,3),
col=c("blue","red","green","purple"))),
auto.key=list(title="Week", cex.title=1, space="right")
)

建议使用这些解决方案而不是直接更改 colpch,因为在构建 key 时也必须更改它们。

另外两个您可能会觉得有启发性的注意事项:首先,尝试使用 factor 而不是 as.character;这将按正确顺序对您的周进行排序。您可以使用 within 来减少输入。

rate <- within(rate, {
Temp <- factor(Temp)
Week <- factor(Week)
Rep <- factor(Rep)
}

其次,查看latticeExtra 包中的useOuterStrips 函数。特别是,如果您的原始绘图保存为 p,请尝试

useOuterStrips(p, strip=strip.custom(strip.names=1),
strip.left=strip.custom(strip.names=1) )

关于r - 如何在 Lattice 中更改绘图字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6333194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com