在轮廓图中控制z标签 [英] Controlling z labels in contourplot
问题描述
我试图控制应使用点阵库中的 contourplot()
绘制的轮廓图中应写入多少z个标签.
我有30条轮廓线,但我只想标记前5条轮廓线.我尝试了很多类似的事情
I am trying to control how many z labels should be written in my contour plot plotted with contourplot()
from the lattice library.
I have 30 contour lines but I only want the first 5 to be labelled. I tried a bunch of things like
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))
但没有任何效果.
还可以在同一张图上绘制两个 contourplot()
吗?我尝试过
Also, is it possible to plot two contourplot()
on the same graph? I tried
contourplot(z ~ z+y, data=d3, cuts=30)
par(new=T)
contourplot(z ~ z+y, data=d3, cuts=20)
但是它不起作用.
谢谢!
but it's not working.
Thanks!
推荐答案
您可以指定 labels
作为字符向量参数,并使用rep(",5)设置最后一个值,所以也许对于您在先前有关轮廓的问题中提供的示例
You can specify the labels
as a character vector argument and set the last values with rep("", 5), so perhaps for the example you offered on an earlier question about contour
x = seq(0, 10, by = 0.5)
y = seq(0, 10, by = 0.5)
z <- outer(x, y)
d3 <- expand.grid(x=x,y=y); d3$z <- as.vector(z)
contourplot(z~x+y, data=d3)
# labeled '5'-'90'
contourplot(z~x+y, data=d3,
at=seq(5,90, by=5),
labels=c(seq(5,25, by=5),rep("", 16) ),
main="Labels only at the first 5 contour lines")
# contourplot seems to ignore 'extra' labels
# c() will coerce the 'numeric' elements to 'character' if any others are 'character'
?contourplot # and follow the link in the info about labels to ?panel.levelplot
这篇关于在轮廓图中控制z标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!