繁体   English   中英

是否可以在方差图中添加线条/文字/小刻度线/个性化轴?

[英]Is it possible to add lines/text/minor tick marks/personalized axes to a variogram plot?

我正在尝试使用plot.variogram函数将文本,线条,小刻度线和/或个性化轴添加到变异函数。 当我尝试使用传统函数调用(例如, text("Text Here") )添加其中任何一个时,它都会返回plot.new has not been called yet的错误, plot.new has not been called yet打开变异函数的绘图窗口, plot.new has not been called yet它。

这是我的代码:

#v is sample variogram, vmf is fitted model
plot(v, model=vmf, xlim=c(0, 65), ylim=c(0,25), xlab="Distance between Point Pairs (km)",
ylab="Semivariance ((C/km) )", cex.xlab=6.5, cex.ylab=6.5, cex.xaxis=2.5, cex.main=5.5)

#Add a 2 to the y label that is in 10 pt. font so it looks like it is (C/km)^2
par(ps=10, cex=1, cex.main=1)
text(-2, 16, labels=2, srt=90)

#Add lines showing the desired point pair distance and semivariance for the problem
par(new=TRUE, lines(c(53,53),c(0,15),col='red'))
par(new=TRUE, lines(c(0, 53),c(15,15),col='red'))

#Add axis minor tick marks in increments of 5
axis(side=1, at=c(0, 5, 15, 25, 35, 45, 55, 65), labels = NA, tck=-0.01, pos=0) 
axis(side=2, at=c(0, 2.5, 7.5, 12.5, 17.5, 22.5, 25),labels = NA, tck=-0.01, pos=0)

我试图通过以下方式“欺骗” R:

plot(c(0,65), c(0,25))

然后运行上面的代码。 这允许传统功能起作用,但不幸的是它们不在适当的位置(即x = 5不在x轴上位于5)。

有什么建议可以更好地“欺骗” R使其正确绘制吗? 是否有将文本,轴等自动添加到方差图的功能?

如果您还有其他想知道的内容,请告诉我。

谢谢!

当使用geoR软件包时,Richard Scriven的答案很好用。

如果使用gstat包,则所有图都需要使用网格图形命令( lattice包和latticeExtra包)进行修改。 plot.new has not been called yet错误plot.new has not been called yet的原因是由于网格图形上使用了基础图形。

样例修改示例:

使用list创建图以修改所有输入参数。 scales会修改x和y轴,您可以添加不带labels刻度线( at )(请参见y轴列表)。 key添加图例。

p1 = plot(v.GF, model=vmf.GF, lwd=2, col.line="black", pch=16, cex=1.5, ylim=c(0,25), xlim=c(0,150), 
      main=list("Gaussian Semivariogram Model for Geothermal Gradient", cex=2),
      xlab=list("Distance between Point Pairs (km)", cex=2), 
      ylab=list(expression("Geothermal Gradient Semivariance (°C/km)"^2), cex=2), 
      scales=list(x=list(at=c(0,25,50,75,100,125,150), labels=c(0,25,50,75,100,125,150)), y=list(at=c(0,2.5,5,7.5,10,12.5,15,17.5,20,22.5,25), labels=c(0,"",5,"",10,"",15,"",20,"",25)), cex=2), 
      key=list(text=list(lab=c("Gaussian Model","Sill","Maximum Interpolation Distance")), space="top", lines=list(col=c("black","black","red"), lwd=2, lty=c(1,2,1)), columns=3, cex=1.5))  

然后使用trellis.focusllines绘制并修改绘图区域,并添加ltextltext添加文本:

trellis.focus("panel",1,1)
plot(p1)
trellis.focus("panel",1,1)
llines(x=c(50,50), y=c(0,14.5), col="red", lwd=2, lty=1)
llines(x=c(0,50), y=c(14.5,14.5), col="red", lwd=2, lty=1)
llines(x=c(0,150), y=c(vmf.GF$psill[2]+vmf.GF$psill[1],vmf.GF$psill[2]+vmf.GF$psill[1]), col="black", lty=2, lwd=2)
ltext(x=12,y=5,"Nugget ~6.0", cex=1.5)
trellis.unfocus()

这是结果图: 在此处输入图片说明

我不确定您如何获得方差图,但是通过使用此链接中的一些代码和信息,我能够获得一些可能对您有所帮助的东西。

使用geoR包,功能variog你可以操纵plot如常。

> sampleV <- 
    read.table(header = TRUE, text = "Station   Av8top      Lat       Lon
  1       60 7.225806 34.13583 -117.9236
  2       69 5.899194 34.17611 -118.3153
  3       72 4.052885 33.82361 -118.1875
  4       74 7.181452 34.19944 -118.5347
  5       75 6.076613 34.06694 -117.7514
  6       84 3.157258 33.92917 -118.2097
  7       85 5.201613 34.01500 -118.0597
  8       87 4.717742 34.06722 -118.2264
  9       88 6.532258 34.08333 -118.1069
  10      89 7.540323 34.38750 -118.5347", row.names = 1)

> library(geoR)
> sampleVMF <- variog(coords = sampleV[,3:4], data = sampleV[,2], 
                      breaks = seq(0, 1.5, length = 11))
> plot(sampleVMF, axes = FALSE,  
       xlab="Distance between Point Pairs (km)",
       ylab="Semivariance ((C/km) )")
> axis(1, at = sampleVMF$u)
> axis(2, at = sampleVMF$v)
> box()
> text(median(sampleVMF$u), median(sampleVMF$v), "Hello world!")
> lines(sampleVMF$u, sampleVMF$v)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM