R - 具有多层(格子)的等高线图
这是我的代码和相关的变量结构。
Correlation_Plot = contourplot(cor_Warra_SF_SST_JJA, region=TRUE, at=seq(-0.8, 0.8, 0.2),
labels=FALSE, row.values=(lon_sst), column.values=lat_sst,
xlab='longitude', ylab='latitude')
Correlation_Plot = Correlation_Plot + layer({ ok <- (cor_Warra_SF_SST_JJA>0.6);
panel.text(cor_Warra_SF_SST_JJA[ok]) })
Correlation_Plot
# this is the longitude (from -179.5 to 179.5) , 360 data in total
> str(lon_sst)
num [1:360(1d)] -180 -178 -178 -176 -176 ...
# this is the latitude (from -89.5 to 89.5), 180 data in total
> str(lat_sst)
num [1:180(1d)] -89.5 -88.5 -87.5 -86.5 -85.5 -84.5 -83.5 -82.5 -81.5 -80.5 ...
# This is data set corresponding to longitude and latitude
> dim(cor_Warra_SF_SST_JJA)
[1] 360 180
我尝试使用 layer()
显示标签以使轮廓更大大于0.6,但不起作用。
是否可以增加图例中的颜色对比度,以便可以真正清楚什么颜色对应什么级别。什么是颜色选项,我找不到它们?
最重要的是我想在指定的轮廓间隔(例如+/- 0.2)内绘制一条较粗的黑线?我想我也可以用
layer()
来做,但我不确定我应该使用什么panel
函数。另外,我尝试用纯色填充大陆,但我找不到任何东西。 我尝试过使用地图,但它不适用于晶格。
感谢您的帮助。
Here is my code and associated variable structures.
Correlation_Plot = contourplot(cor_Warra_SF_SST_JJA, region=TRUE, at=seq(-0.8, 0.8, 0.2),
labels=FALSE, row.values=(lon_sst), column.values=lat_sst,
xlab='longitude', ylab='latitude')
Correlation_Plot = Correlation_Plot + layer({ ok <- (cor_Warra_SF_SST_JJA>0.6);
panel.text(cor_Warra_SF_SST_JJA[ok]) })
Correlation_Plot
# this is the longitude (from -179.5 to 179.5) , 360 data in total
> str(lon_sst)
num [1:360(1d)] -180 -178 -178 -176 -176 ...
# this is the latitude (from -89.5 to 89.5), 180 data in total
> str(lat_sst)
num [1:180(1d)] -89.5 -88.5 -87.5 -86.5 -85.5 -84.5 -83.5 -82.5 -81.5 -80.5 ...
# This is data set corresponding to longitude and latitude
> dim(cor_Warra_SF_SST_JJA)
[1] 360 180
I tried to use layer()
to show the label just for contour bigger than 0.6, but it doesn't work.
Is it possible to increase the colour contrasts in the legend so it can be really clear what colour responds to what level. What are colour options, i can't find them?
The most important is I want to draw a thicker black line for a specified contour interval (e.g. for +/- 0.2)? I think ican do it with
layer()
as well, but i am not sure whatpanel
function should i use.Also, i tried to fill in the continent with a solid colour, but i can't find any thing with it.
I have tried use map, but it doesn't work for lattice.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看
?panel.levelplot
以了解contourplot
的其他参数。您可以使用
col.regions
参数,该参数将采用您想要与间隔相对应的颜色向量或颜色渐变函数(例如下面)。使用自定义面板函数,如下所示(使用使用 Santiago Beguería 的博客)。使用
lpolygon
绘制地图对象:生成虚拟数据集:
<前><代码>库(gstat)
# 创建结构
xy <- 展开.grid(1:360, 1:180)
名称(xy) <- c('x','y')
# 定义 gstat 对象(空间模型)
g.dummy <- gstat(公式=z~1, 位置=~x+y, dummy=T, beta=1,
模型=vgm(psill=0.025,模型='Exp',范围=5),nmax=20)
# 基于 gstat 对象进行模拟
yy <- 预测(g.dummy, newdata=xy, nsim=1)
网格化(yy) = ~x+y
# 缩放到范围 [-1, 1]
z <- 矩阵(yy@data[, 1], ncol=180)
z.scalefac <- (max(z) - min(z)) / 2
z <- -1 + (z - min(z)) / z.scalefac
绘图:
Take a look at
?panel.levelplot
for additional arguments tocontourplot
.You can use the
col.regions
argument, which will take either a vector of colours that you'd like to correspond to your intervals, or a color ramp function (e.g. below).Use a custom panel function, something like this (using a spatially autocorrelated dummy dataset generated using a method given on Santiago Beguería's blog). Use
lpolygon
to plot the map object:Generate dummy dataset:
Plot:
Q1:您需要使用
llines
或panel.lines
以及上一个问题中用于大陆轮廓的相同数据来执行此操作Q2:
...其中它说“lwd”是一个可用选项,我怀疑您会使向量的第七个元素 = 2。
Q3:可能是一个填充参数,但必须指出的是,您严重阻碍了我们测试解决方案的努力包括数据和您的数据的链接 准备。
Q1: You will need to use
llines
orpanel.lines
with the same data you used for the continental outlines in the previous question to do thatQ2:
.... Wherein it says that "lwd" is an available option and I suspect that you would make the seventh element of a vector = 2.
Q3: Probably a fill argument, but it must be noted that you are seriously inhibiting our efforts at testing solutions by not including a link to the data and your data preparation.