## note that we need to define this function before we can use it
## put all of the plotting commands into a wrapper function:
plot_xrd <- function(d)
{
## plot the difractograms offset by 200
plot(MG ~ x, data=d, type="l", cex=.25, main="Tioga1 35-65cm", xlab="2 Theta", ylab="Intensity", xlim=c(2,32), ylim=c(0,1600), xaxt='none')
## add the other treatments
lines(MG_GLY + 200 ~ x, data=d)
lines(K + 400 ~ x, data=d)
lines(K_350 + 600 ~ x, data=d)
lines(K_550 + 800 ~ x, data=d)
## label the lines
text(31.5, c(30,230,430,630,830), c("MG","MG+GLY","K25","K350","K550"))
## plot the zero-line on each graph:
abline(h=c(0,200,400,600,800), lty=2, col="gray")
## plot the established boundaries to these common spacings
abline(v=(asin(0.154/(2*c(0.71,0.73,0.72,0.75,0.99,1.01,1.24,1.28,1.4,1.5,1.77,1.8))) * 180/pi * 2), col="green", lty=2)
## plot some common d-spacings
# abline(v=(asin(0.154/(2*c(.715,.73,1,1.2,1.4,1.8))) * 180/pi * 2), col="blue")
## annotate the lines, recall that d-spacing is in reverse order with respect to Two_theta
text((asin(0.154/(2*c(.715,.73,1,1.2,1.4,1.8))) * 180/pi * 2), c(1300,1400,1400,1400,1400,1400), c(".715",".73","1.0","1.2","1.4","1.8"), col=1, cex=1)
## add the axis
axis(1, 1:30)
}
##
##
##
## load some sample data
d <- read.csv("tioga1_35-65.csv", header=FALSE)
## name the columns
names(d) <- c('x', 'MG', 'MG_GLY', 'K', 'K_350', 'K_550')
## run the wrapper function to plot the Tioga1 0-8cm data:
plot_xrd(d)