I'm trying to add text, lines, minor tick marks, and/or personalized axes to a variogram using the plot.variogram
function. When I try to add any of these using the traditional function calls (i.e. text("Text Here")
) it returns the error of plot.new has not been called yet
even though the plotting window for the variogram is open.
Here is my code:
#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)
I have tried to "trick" R by calling:
plot(c(0,65), c(0,25))
and then running the code above. This allows for the traditional functions to work, but they are unfortunately not in the appropriate locations (i.e. x=5 is not located at 5 on the x axis).
Any recommendations for better ways to "trick" R to plotting correctly? Any functions that add text, axes, etc. automatically to variogram plots?
Please let me know if there's anything else you would like to know.
Thanks!