【问题标题】:R: levelplot (some values are missing in the contour)R:levelplot(轮廓中缺少一些值)
【发布时间】:2013-07-29 22:21:03
【问题描述】:

我有一个 3d 数据,x,y,z。我在 R 中使用 levelplot,但结果看起来不正确。如果我查看任何水平线(例如 y=0),我希望在图中看到对应于值 z=0 的一些蓝色区域。因此,基本上,如果您考虑任何水平线,您应该会看到一些蓝色区域,但您只能看到顶部的蓝色区域。

这是等高线图:

所以,我正在努力解决这个问题!它与panel.2dsmoother有什么关系吗?我的数据的 x 范围从 3.12 到 14.88,增量为 0.48,y 值范围从 0 到 24,增量为 4。

还有完整的数据和代码在这里:

> d<-read.csv("test.csv", header=F, col.names=c("x", "y", "z"))
> library(latticeExtra)
> col.l <- colorRampPalette(c('blue', 'cyan', 'green', 'yellow', 'orange', 'red'))
> col.divs<-20
> levelplot(z ~ x * y, d, cuts=50, contour=TRUE, col.regions=col.l,
      at=seq(from=-0.2,to=4,length=col.divs), panel=panel.2dsmoother)
> d
        x  y       z
1    3.12  0  6.4239
2    3.60  0  2.5190
3    4.08  0  0.1210
4    4.56  0  0.0028
5    5.04  0  0.3355
6    5.52  0  1.7268
7    6.00  0  2.5390
8    6.48  0  2.9881
9    6.96  0  3.2323
10   7.44  0  3.3670
11   7.92  0  3.4217
12   8.40  0  3.4088
13   8.88  0  3.4111
14   9.36  0  3.3956
15   9.84  0  3.3612
16  10.32  0  3.3392
17  10.80  0  3.3003
18  11.28  0  3.2952
19  11.76  0  3.2732
20  12.24  0  3.2439
21  12.72  0  3.2298
22  13.20  0  3.2191
23  13.68  0  3.1844
24  14.16  0  3.1678
25  14.64  0  3.1521
26   3.12  4  6.5401
27   3.60  4  2.5084
28   4.08  4  0.1261
29   4.56  4  0.0179
30   5.04  4  0.4792
31   5.52  4  1.7951
32   6.00  4  2.6164
33   6.48  4  3.0780
34   6.96  4  3.3126
35   7.44  4  3.4253
36   7.92  4  3.4709
37   8.40  4  3.4824
38   8.88  4  3.4901
39   9.36  4  3.4814
40   9.84  4  3.4540
41  10.32  4  3.4346
42  10.80  4  3.4142
43  11.28  4  3.4252
44  11.76  4  3.4151
45  12.24  4  3.3993
46  12.72  4  3.3876
47  13.20  4  3.3645
48  13.68  4  3.3313
49  14.16  4  3.3187
50  14.64  4  3.2959
51   3.12  8  6.5561
52   3.60  8  2.5146
53   4.08  8  0.1481
54   4.56  8  0.0414
55   5.04  8  0.1537
56   5.52  8  1.6942
57   6.00  8  2.5457
58   6.48  8  3.0397
59   6.96  8  3.2660
60   7.44  8  3.3709
61   7.92  8  3.4198
62   8.40  8  3.4320
63   8.88  8  3.4434
64   9.36  8  3.4431
65   9.84  8  3.4163
66  10.32  8  3.3798
67  10.80  8  3.3610
68  11.28  8  3.3196
69  11.76  8  3.3142
70  12.24  8  3.2818
71  12.72  8  3.2514
72  13.20  8  3.2395
73  13.68  8  3.2068
74  14.16  8  3.1747
75  14.64  8  3.1422
76   3.12 12  6.6538
77   3.60 12  2.3232
78   4.08 12  0.1410
79   4.56 12  0.0000
80   5.04 12 -0.2133
81   5.52 12  0.9858
82   6.00 12  1.5389
83   6.48 12  1.7809
84   6.96 12  1.8857
85   7.44 12  1.9518
86   7.92 12  1.9630
87   8.40 12  1.9603
88   8.88 12  1.9357
89   9.36 12  1.9004
90   9.84 12  1.8829
91  10.32 12  1.8673
92  10.80 12  1.8307
93  11.28 12  1.7922
94  11.76 12  1.7919
95  12.24 12  1.7501
96  12.72 12  1.7178
97  13.20 12  1.6887
98  13.68 12  1.6583
99  14.16 12  1.6334
100 14.64 12  1.6093
101  3.12 16  6.5478
102  3.60 16  2.3706
103  4.08 16  0.8842
104  4.56 16  0.0540
105  5.04 16  0.0361
106  5.52 16  0.0068
107  6.00 16  0.0491
108  6.48 16  0.0034
109  6.96 16  0.0551
110  7.44 16  0.0706
111  7.92 16  0.1714
112  8.40 16  0.1576
113  8.88 16  0.1432
114  9.36 16  0.1147
115  9.84 16  0.0546
116 10.32 16  0.0362
117 10.80 16  0.0330
118 11.28 16  0.0241
119 11.76 16  0.0085
120 12.24 16 -0.0146
121 12.72 16 -0.0176
122 13.20 16 -0.0380
123 13.68 16 -0.0628
124 14.16 16 -0.0883
125 14.64 16 -0.0983
126  3.12 20  6.0197
127  3.60 20  1.8706
128  4.08 20  0.6259
129  4.56 20  0.0810
130  5.04 20  0.0040
131  5.52 20  0.0213
132  6.00 20  0.0986
133  6.48 20  0.1801
134  6.96 20  0.2576
135  7.44 20  0.3037
136  7.92 20 -0.2892
137  8.40 20  0.2882
138  8.88 20  0.2697
139  9.36 20  0.2604
140  9.84 20  0.2574
141 10.32 20  0.2368
142 10.80 20  0.2061
143 11.28 20  0.1816
144 11.76 20  0.1639
145 12.24 20  0.1455
146 12.72 20  0.1387
147 13.20 20  0.1011
148 13.68 20  0.0901
149 14.16 20  0.0687
150 14.64 20  0.0564
151  3.12 24  5.9622
152  3.60 24  1.8736
153  4.08 24  0.6328
154  4.56 24  0.1683
155  5.04 24  0.0167
156  5.52 24  0.0339
157  6.00 24  0.0787
158  6.48 24  0.1617
159  6.96 24  0.2204
160  7.44 24  0.2432
161  7.92 24  0.2641
162  8.40 24  0.2472
163  8.88 24  0.2171
164  9.36 24  0.2048
165  9.84 24  0.1796
166 10.32 24  0.1473
167 10.80 24  0.1227
168 11.28 24  0.1433
169 11.76 24  0.1093
170 12.24 24  0.0769
171 12.72 24  0.0446
172 13.20 24  0.0247
173 13.68 24 -0.0015
174 14.16 24 -0.0197
175 14.64 24 -0.0439

如果我删除了 panel.2dsmoother

levelplot(z ~ x * y, d, cuts=30, col.regions=col.l, at=seq(from=-0.2,to=4,length=col.divs))

然后它看起来像这样:

但这不是我想要的。例如,octave (MATLAB) 给了我这个具有相同数据的轮廓,这很好!所以,我想用 R 生成相同的图(如果可能的话)

八度:

【问题讨论】:

  • 我不明白您提供的材料如何让我们了解您想要什么或为什么您认为 levelplot 提供了不正确的结果。你想要蓝色区域,你得到了一些。我们无法确定位置是否正确,因为我们看不到任何 x 或 y 值。
  • @Dwin 想说的是,如果您 (1) 发布了所有 dat,而不仅仅是子集,并且 (2) 解释了为什么您希望看到其他内容,那将会很有帮助比你所拥有的
  • 是的,很抱歉!我编辑了问题并提供了完整的数据!现在清楚了吗?

标签: r panel contour smoothing levelplot


【解决方案1】:

默认设置看起来对您的数据过于平滑。您可以传递适当的 span 参数来解决此问题。这是控制平滑量的参数;它被loess 使用,这是panel.2dsmoother2 在后台调用的。详情请见?loess

levelplot(...., panel=panel.2dsmoother, args=list(span=0.5))

我凭空选择了值 0.5(默认值为 0.75;较小的值执行的平滑度较低)。您可以尝试不同的值,看看哪种效果最好。

【讨论】:

  • 谢谢,解决了!还有一件事,我怎样才能提高它的分辨率?
【解决方案2】:

是的,panel.2dsmoother 平滑了相对较小的零区域。 尝试移除平滑器,例如使用它可以看到蓝色区域。

 levelplot(z ~ x * y, d, col.regions=col.l, cuts=30) 

【讨论】:

  • 没错,但这看起来不太好!我可以进行其他类型的平滑处理吗?
猜你喜欢
  • 2012-08-20
  • 2017-06-27
  • 2019-11-07
  • 2021-08-29
  • 2021-03-10
  • 2018-09-29
  • 2013-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多