R 是否可以将线条/文字/小记号/个性化轴添加到变异函数图中?

R 是否可以将线条/文字/小记号/个性化轴添加到变异函数图中?,r,plot,personalization,kriging,gstat,R,Plot,Personalization,Kriging,Gstat,我正在尝试使用plot.variagram函数将文本、线条、小记号和/或个性化轴添加到变异函数中。当我尝试使用传统函数调用(即text(“text Here”))添加其中任何一个函数时,它返回plot.new的错误,尽管变差函数的绘图窗口已打开,但尚未调用 这是我的密码: #v is sample variogram, vmf is fitted model plot(v, model=vmf, xlim=c(0, 65), ylim=c(0,25), xlab="Distance betwee

我正在尝试使用
plot.variagram
函数将文本、线条、小记号和/或个性化轴添加到变异函数中。当我尝试使用传统函数调用(即
text(“text Here”)
)添加其中任何一个函数时,它返回
plot.new的错误,尽管变差函数的绘图窗口已打开,但尚未调用

这是我的密码:

#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
软件包,函数
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)
>样本库(geoR)
>sampleVMF绘图(sampleVMF,轴=假,
xlab=“点对之间的距离(km)”,
ylab=“半方差((C/km))”)
>轴(1,at=sampleVMF$u)
>轴(2,at=sampleVMF$v)
>框()
>文本(中间值(sampleVMF$u),中间值(sampleVMF$v),“Hello world!”)
>行(sampleVMF$u、sampleVMF$v)

使用
geoR
软件包时,Richard Scriven的答案非常有效

如果使用
gstat
软件包,则所有绘图都需要使用网格图形命令(
lattice
package和
latticetextra
package)进行修改。尚未调用
plot.new的错误原因是因为基本图形使用在网格图形上

绘图修改示例:

使用
list
创建绘图,以修改所有输入参数。
缩放
修改x轴和y轴,您可以添加勾号(
位于
),而无需
标签
(请参见y轴列表)。
键添加图例

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))  
然后使用
grillis.focus
llines
添加行和
ltext
添加文本来打印和修改打印区域:

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包而不是gstat包。geoR包中的variog命令可用于创建变异函数,然后variofit命令可用于拟合变异函数。我还想知道是否可以使用gstat包添加这些功能。将代码转换为使用geoR不是问题,只是好奇而已。