如何在Lattice中向轮廓图添加单个新轮廓 [英] How to add a single new contour to a contour plot in Lattice

查看:66
本文介绍了如何在Lattice中向轮廓图添加单个新轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用莱迪思软件包中的轮廓图函数生成了一个填充的轮廓图.我希望能够强调此功能所产生的轮廓线之一,例如通过改变lwd = 2,并去加重产生的其他轮廓线,例如通过将其余轮廓线颜色设置为灰色.

I have produced a filled contourplot using contourplot function in the Lattice package. I would like to be able to emphasise one of the contour lines produced by this function, e.g. by changing lwd=2, and de-emphasise the other contour lines produced, e.g. by setting changing the remaining contour line colours to grey.

例如,我想要添加等价物

For example, I would like the equivalent of adding

contourplot(
Male ~ Year * Age, 
data=this.ds, region=F, labels=F, lwd=2, at=c(0, 0.01, 1))

收件人

contourplot(
Male ~ Year * Age, 
data=this.ds, 
region=T, col.regions=rev(heat.colors(200)), 
cuts=50, main="", sep="") 

我认识到答案很可能涉及功能更新,面板和/或层(如果使用gridExtra),但是我对晶格对象的基本逻辑/结构的理解不足以弄清楚该做什么.做.

I recognise that the answer is likely to involve the functions update, panel, and/or layer (if using latticeExtra), but I my understanding of the underlying logic/structure of lattice objects is not good enough to figure out what to do.

感谢您的帮助.我基本上使用了第一个答案,但进行了以下稍微的修改,以便能够在轮廓线上指出几个特征:

Thanks for your help. I basically used the first answer, but with the following slight modification to be able to point out a couple of features on the contour line:

require(lattice)
require(latticeExtra)

Part1 <- contourplot(Female ~ Year * Age, 
                     data=this.ds,
                     region=T, 
                     col.regions=rev(heat.colors(200)),
                     cuts=50, 
                     main="", 
                     labels=F,
                     col="grey",
                     sep="")

Part2 <- contourplot(Female ~ Year * Age,
                     data=this.ds,
                     region=F,
                     labels=F,
                     lwd=2,
                     at=c(0, 0.01, 1),
                     panel=function(...){
                     panel.contourplot(...)
                      panel.segments(x0=c(1840, 1900, 2000, 1840), 
                                     x1=c(1900, 1900, 2000, 2000), 
                                     y0=c(40.5, 0, 0, 64), 
                                     y1=c(40.5, 40.5, 64, 64), 
                                     lty="dashed")
                     }                    
)


Plot.Final <- Part1+ Part2 

print(Plot.Final)

推荐答案

加载gridExtra库.然后:

Load the latticeExtra library. Then:

Part1<-contourplot(
    Male ~ Year * Age, 
    data=this.ds, 
    region=T, col.regions=rev(heat.colors(200)), 
    cuts=50, main="", sep="")

Part2<-contourplot(
    Male ~ Year * Age, 
    data=this.ds, region=F, labels=F, lwd=2, at=c(0, 0.01, 1))

Plot.Final<-Part1+Part2

这应该根据需要组合图形.如果需要,您可能需要设置xlim,ylim和标签,以便一切正常.

That should combine the graphs as you wish. If needed you may need to set xlim, ylim and labels so that everything looks OK.

这篇关于如何在Lattice中向轮廓图添加单个新轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆