在contourplot中控制z标签

Sno*_*rog 2 r lattice

我试图控制contourplot()在格子库中绘制的轮廓图中应该写入多少z个标签.
我有30条轮廓线,但我只希望标记前5条.我尝试了很多类似的东西

contourplot(z ~ z+y, data=d3, cuts=30, font=3, xlab="x axis", ylab="y axis", scales=list(at=seq(2,10,by=2)))
contourplot(z ~ z+y, data=d3, cuts=30, font=3, xlab="x axis", ylab="y axis", at=seq(2,10,by=2))
Run Code Online (Sandbox Code Playgroud)

但没有任何作用.

此外,是否可以contourplot()在同一图表上绘制两个?我试过了

contourplot(z ~ z+y, data=d3, cuts=30)
par(new=T)
contourplot(z ~ z+y, data=d3, cuts=20)
Run Code Online (Sandbox Code Playgroud)

但它不起作用.
谢谢!

chl*_*chl 6

这是我的看法:

library(lattice)
x <- rep(seq(-1.5,1.5,length=50),50)
y <- rep(seq(-1.5,1.5,length=50),rep(50,50))
z <- exp(-(x^2+y^2+x*y))

# here is default plot
lp1 <- contourplot(z~x*y)    

# here is an enhanced one
my.panel <- function(at, labels, ...) { 
    # draw odd and even contour lines with or without labels
    panel.contourplot(..., at=at[seq(1, length(at), 2)], col="blue", lty=2)
    panel.contourplot(..., at=at[seq(2, length(at), 2)], col="red",
                      labels=as.character(at[seq(2, length(at), 2)]))
} 

lp2 <- contourplot(z~x*y, panel=my.panel, at=seq(0.2, 0.8, by=0.2))
lp3 <- update(lp2, at=seq(0.2,0.8,by=0.1))
lp4 <- update(lp3, lwd=2, label.style="align")

library(gridExtra)
grid.arrange(lp1, lp2, lp3, lp4)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

您可以调整自定义panel功能以最好地满足您的需求(例如,用于调平z轴,颜色等的其他比例).