setwd("/doi_10.5061_dryad.xgxd254bs__v1/") qwp<-read.csv("QWP Retarder Film Measurement, data.csv", header=TRUE) # Dimension names, Wavelength, Angle of QWP, Angle of Analyser Polarizing Filter WL<-qwp$WL qwp.angle<-c(97,93,91,90,89,85,81,77,73,69,65,61,57,53,49,46,45,44,43,41,39,35,31,27,23,19,15,11,7,3,1,0,-1,-5) pol.angle<-c(135,90,45,0) #Convert imported data into 3d matrix qwp<-as.vector(as.matrix(qwp[-1])) dim(qwp)<-c(3648,4,34) dimnames(qwp)<-list(WL,pol.angle,qwp.angle) #---------------- Degree of Polarization---------------------------------- #Calculate Degree of Polarization (p) p<-sqrt((qwp[,4,]-qwp[,2,])^2 +(qwp[,3,]-qwp[,1,])^2)/((qwp[,4,]+qwp[,2,]+qwp[,3,]+qwp[,1,])/2) #Calculate degree of polarization for all wavelength based on angle of QWP (0-90°) dp.at.qwp.angle<-function(qwp.a){ sapp.fun<-function(x){ approx(x=as.numeric(unlist(dimnames(p)[2])), y=p[x,], xout=qwp.a)$y } cbind(as.numeric(unlist(dimnames(p)[1])), sapply(seq(1,length(p[,1]),1), sapp.fun)) } #Set figure width and calculate plot sizes and figure height #All inputs in inches f_width<-7 m_bottom<-0.5 m_left<-0.75 m_top<-0.25 m_right<-0.85 p_width<-f_width-m_left-m_right p_height<-1*p_width/3 f_height<-p_height+m_bottom+m_top #Graph Ranges xlim<-c(0, 90) ylim<-c(0,100) #This trims graphed data to rotation angles from 0-90° qwp.angle.corr<-(qwp.angle)>=0 & (qwp.angle)<=90 p.subset<-p[,qwp.angle.corr] qwp.angle.corr<-qwp.angle[qwp.angle.corr] #Plotted wavelength and corresponding colors plot.WL<-seq(400, 800, 50) colors<-c(hsv(280/360,1,1),hsv(240/360,1,1), hsv(170/360,1,1), hsv(110/360,1,1), hsv(50/360,1,1), hsv(0/360,1,1), hsv(0/360,1,0.75), hsv(0/360,0.5,0.5), hsv(0/360,0,0)) #Export figure to a pdf with the width and height from above pdf("QWP rotation d-pol.pdf", width=f_width, height=f_height) #Margins par(mai=c(m_bottom,m_left,m_top,m_right), xpd=NA) #xpd=NA allows drawing outside the plot area plot.new() plot.window(xlim=xlim, ylim=ylim, xaxs="i", yaxs="i") lines(c(45,45),ylim, col=hsv(1,0,0.5)) plot.line<-function(x) lines(qwp.angle.corr, 100*p.subset[which.min(abs(WL - x)),], col=colors[which(plot.WL==x)]) lapply(plot.WL, plot.line) axis(1, at=seq(xlim[1], xlim[2], 15), mgp=c(3, 0.20, 0), tck=-0.025, cex.axis=0.7) axis(2, at=seq(ylim[1], ylim[2], 10), mgp=c(3, 0.70, 0), tck=-0.025, las=1, cex.axis=0.7) mtext("Angle of rotation of quarter wave retarder film (°)", side=1, line=1.25, cex=0.8) mtext("Degree of linear polarization (%)", side=2, line=2, cex=0.8) legend(96.5, 50, title="Wavelength", paste(plot.WL, "nm"), xjust=0.5, yjust=0.5, lty=1, seg.len=1.5, col=colors, cex=0.7, bty="n") box() #Close Graph dev dev.off() #----------------------- #Set figure width and calculate plot sizes and figure height #All inputs in inches f_width<-7 m_bottom<-0.5 m_left<-0.75 m_top<-0.25 m_right<-0.85 p_width<-f_width-m_left-m_right p_height<-1*p_width/3 f_height<-p_height+m_bottom+m_top #Graph Ranges xlim<-c(350, 850) ylim<-c(0,100) WL.subset<-WL[WL>=350 & WL<=850] #Export figure to a pdf with the width and height from above pdf("QWP rotation d-pol2.pdf", width=f_width, height=f_height) #Margins par(mai=c(m_bottom,m_left,m_top,m_right), xpd=NA) #xpd=NA allows drawing outside the plot area plot.new() plot.window(xlim=xlim, ylim=ylim, xaxs="i", yaxs="i") box() lines(WL.subset,p[WL>=350 & WL<=850,4]*100, col=hsv(1,0,0.8)) lines(WL.subset,p[WL>=350 & WL<=850,17]*100, col=hsv(1,0,0.0)) axis(1, at=seq(xlim[1], xlim[2], 50), mgp=c(3, 0.20, 0), tck=-0.025, cex.axis=0.7) axis(2, at=seq(ylim[1], ylim[2], 10), mgp=c(3, 0.70, 0), tck=-0.025, las=1, cex.axis=0.7) mtext("Wavelength (nm)", side=1, line=1.25, cex=0.8) mtext("Degree of linear polarization (%)", side=2, line=2, cex=0.8) legend(890, 40, title="Angle of \nrotation of \nquarter wave \nretarder film", c("0°", "45°"), xjust=0.5, yjust=0.5, lty=1, seg.len=1.5, col=c(hsv(1,0,0.8),hsv(1,0,0.0)), cex=0.7, bty="n") #Close Graph dev dev.off() #---------------- Axis of Polarization ---------------------------------------- degrees<-function(x) (360*x)/(2*pi) #Calculate Degree of Polarization (a) a<-degrees(0.5*atan2(qwp[,3,]-qwp[,1,], qwp[,4,]-qwp[,2,])) a<-lapply(a, function(x) ifelse(x < 0, x+180, x)) dim(a)<-c(3648, 34) dimnames(a)<-list(WL,qwp.angle) #Calculate degree of polarization for all wavelengths based on angle of QWP (0-90°) a.at.qwp.angle<-function(qwp.a){ sapp.fun<-function(x){ approx(x=as.numeric(unlist(dimnames(a)[2])), y=a[x,], xout=qwp.a)$y } cbind(as.numeric(unlist(dimnames(a)[1])), sapply(seq(1,length(a[,1]),1), sapp.fun)) } #Set figure width and calculate plot sizes and figure height #All inputs in inches f_width<-7 m_bottom<-0.5 m_left<-0.75 m_top<-0.25 m_right<-0.85 p_width<-f_width-m_left-m_right p_height<-1*p_width/3 f_height<-p_height+m_bottom+m_top #Graph Ranges xlim<-c(0, 90) ylim<-c(0,180) #This trims graphed data to rotation angles from 0-90° qwp.angle.corr<-(qwp.angle)>=0 & (qwp.angle)<=90 a.subset<-a[,qwp.angle.corr] qwp.angle.corr<-qwp.angle[qwp.angle.corr] #Plotted wavelength and corresponding colors plot.WL<-seq(400, 800, 50) colors<-c(hsv(280/360,1,1),hsv(240/360,1,1), hsv(170/360,1,1), hsv(110/360,1,1), hsv(50/360,1,1), hsv(0/360,1,1), hsv(0/360,1,0.75), hsv(0/360,0.5,0.5), hsv(0/360,0,0)) #Export figure to a pdf with the width and height from above pdf("QWP rotation a-pol.pdf", width=f_width, height=f_height) #Margins par(mai=c(m_bottom,m_left,m_top,m_right), xpd=NA) #xpd=NA allows drawing outside the plot area plot.new() plot.window(xlim=xlim, ylim=ylim, xaxs="i", yaxs="i") lines(c(45,45),ylim, col=hsv(1,0,0.5)) plot.line<-function(x) lines(qwp.angle.corr, a.subset[which.min(abs(WL - x)),], col=colors[which(plot.WL==x)]) lapply(plot.WL, plot.line) axis(1, at=seq(xlim[1], xlim[2], 15), mgp=c(3, 0.20, 0), tck=-0.025, cex.axis=0.7) axis(2, at=seq(ylim[1], ylim[2], 15), mgp=c(3, 0.70, 0), tck=-0.025, las=1, cex.axis=0.7) mtext("Angle of rotation of quarter wave retarder film (°)", side=1, line=1.25, cex=0.8) mtext("Axis of polarization (°)", side=2, line=2, cex=0.8) legend(96.5, 90, title="Wavelength", paste(plot.WL, "nm"), xjust=0.5, yjust=0.5, lty=1, seg.len=1.5, col=colors, cex=0.7, bty="n") box() #Close Graph dev dev.off() #----------------------- #Set figure width and calculate plot sizes and figure height #All inputs in inches f_width<-7 m_bottom<-0.5 m_left<-0.75 m_top<-0.25 m_right<-0.85 p_width<-f_width-m_left-m_right p_height<-1*p_width/3 f_height<-p_height+m_bottom+m_top #Graph Ranges xlim<-c(350, 850) ylim<-c(0,180) WL.subset<-WL[WL>=350 & WL<=850] #Export figure to a pdf with the width and height from above pdf("QWP rotation a-pol2.pdf", width=f_width, height=f_height) #Margins par(mai=c(m_bottom,m_left,m_top,m_right), xpd=NA) #xpd=NA allows drawing outside the plot area plot.new() plot.window(xlim=xlim, ylim=ylim, xaxs="i", yaxs="i") box() lines(WL.subset,a[WL>=350 & WL<=850,4], col=hsv(1,0,0.0)) lines(WL.subset,a[WL>=350 & WL<=850,16], col=hsv(1,0,0.4)) lines(WL.subset,a[WL>=350 & WL<=850,18], col=hsv(1,0,0.8)) axis(1, at=seq(xlim[1], xlim[2], 50), mgp=c(3, 0.20, 0), tck=-0.025, cex.axis=0.7) axis(2, at=seq(ylim[1], ylim[2], 15), mgp=c(3, 0.70, 0), tck=-0.025, las=1, cex.axis=0.7) mtext("Wavelength (nm)", side=1, line=1.25, cex=0.8) mtext("Axis of polarization (°)", side=2, line=2, cex=0.8) legend(890, 80, title="Angle of \nrotation of \nquarter wave \nretarder film", c("0°", "46°", "44°"), xjust=0.5, yjust=0.5, lty=1, seg.len=1.5, col=c(hsv(1,0,0.0),hsv(1,0,0.4),hsv(1,0,0.8)), cex=0.7, bty="n") #Close Graph dev dev.off()