这是我的代码和相关的变量结构。
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)?我认为ican也会使用layer()
,但我不确定应该使用panel
函数。
此外,我试图用纯色填充大陆,但我找不到任何东西。 我尝试过使用map,但它不适用于格子。
感谢您的帮助。
答案 0 :(得分:5)
查看?panel.levelplot
以获取contourplot
的其他参数。
您可以使用col.regions
参数,该参数将采用您想要与您的间隔对应的颜色矢量或颜色渐变功能(例如下面的颜色)。
使用自定义面板函数,类似于此(使用Santiago Beguería's blog上给出的方法生成的空间自相关虚拟数据集)。使用lpolygon
绘制地图对象:
生成虚拟数据集:
library(gstat)
# create structure
xy <- expand.grid(1:360, 1:180)
names(xy) <- c('x','y')
# define the gstat object (spatial model)
g.dummy <- gstat(formula=z~1, locations=~x+y, dummy=T, beta=1,
model=vgm(psill=0.025,model='Exp',range=5), nmax=20)
# make a simulations based on the gstat object
yy <- predict(g.dummy, newdata=xy, nsim=1)
gridded(yy) = ~x+y
# scale to range [-1, 1]
z <- matrix(yy@data[, 1], ncol=180)
z.scalefac <- (max(z) - min(z)) / 2
z <- -1 + (z - min(z)) / z.scalefac
简介:
library(lattice)
library(maps)
lon_sst <- seq(-179.5, 179.5, 1)
lat_sst <- seq(-89.5, 89.5, 1)
colramp <- colorRampPalette(c('red', 'yellow', 'white', 'green', 'blue'))
contourplot(z, xlim=c(100, 160), ylim=c(-80, -50),
at=seq(-1, 1, 0.2), region=TRUE, col.regions=colramp,
row.values=lon_sst, column.values=lat_sst, labels=FALSE,
xlab='longitude', ylab='latitude',
panel = function(at, region, ...) {
panel.contourplot(at=at, region=TRUE, ...)
panel.contourplot(at=c(-0.2, 0.2), lwd=2, region=FALSE, ...)
mp <- map("world", "antarctica", plot = FALSE, fill=TRUE)
lpolygon(mp$x, mp$y, fill=TRUE, col='gray')
})
答案 1 :(得分:1)
问题1:您需要使用llines
或panel.lines
与上一个问题中用于大陆大纲的相同数据来执行此操作
Q2:
?panel.contour
....其中它说“lwd”是一个可用的选项,我怀疑你会使vector的第七个元素= 2.
第三季度:可能是一个填充论点,但必须指出的是,你严重抑制了我们在测试解决方案方面的努力,不包括数据链接和数据准备。