To demonstrate the capability of this package, here is an example of a materials application for the Zirconia, Alumina, Silica system via reproducing the results depicted in the work by Sorrell and Sorrell [1]. Lets firstly present the result prior to presenting the code/method on how it was produced.
Case Study Final Output:
Procedures to Achieve the Above:
- Data preparation, and,
- Construction of the plot by progressively adding layers.
Keep reading for details on each…
Data Preparation:
The first step is to input the data points, from the paper, we have explicit data points, phase lines, text labels etc.
#Input the data 24 points in total. df <- data.frame(Al2O3 = c(0, 5,10,10,2,2,1,1,3,2,1,3,1,3, 1,0,0,.10,.275,.500,.075,.50,.025,.20), ZrO2 = c(2,40,40,45,2,2,2,2,2,2,2,2,0,0, 0,1,0,.60,.450,.175,.325,.25,.450,.55), SiO2 = c(2,55,50,45,2,0,2,3,2,3,4,3,2,2, 0,0,1,.30,.275,.325,.600,.25,.525,.25), Al2O3end= NA, ZrO2end = NA, SiO2end = NA, #FOR USE LATER Group = c(rep("Data",14), #First 14 pts are 'Data' rep("Compound",3), #Next 3 'Compound info' rep("Phase",3), #Next 3 phase labels rep("BndApprxBC",2), #Next 2 BC Boundary rep("BndApprxAB",2)), #Final 2 AB Boundary label = c("Zircon", rep("",12), "Mullite",rep("",3), "A","B","C", rep("",4)), phase = c("A",rep("B",8),rep("C",5), "A","B","C", "A","B","C","BC","BC","AB","AB"), hjust = c(1.1,rep(NA,12),-0.1,rep(NA,10)), vjust = c(-0.75,rep(-0.75,12),-0.75,rep(NA,10)), linetype= NA)
Create the paths based on start and finish indexes in the above dataset.
#Create the path indexes & data df.paths <- data.frame(id.start=c(16,14,1,21,23), id.end =c(14,1,15,22,24), linetype=c(1,1,2,1,1)) df.paths.res <- cbind(df[df.paths$id.start,c(1:3)],df[df.paths$id.end,c(1:3)]) colnames(df.paths.res)[4:6] <- paste(colnames(df.paths.res)[4:6],"end",sep="") #Ensure the same columns exist prior to merging. df.paths.res$Group = c(rep("Paths",3),rep("Boundaries",2)) df.paths.res$label = "" df.paths.res$linetype = df.paths$linetype df.paths.res$hjust = NA df.paths.res$vjust = NA df.paths.res$phase = c("AC","CA","AC","BC","AB")
Merge the two sets to create a master dataframe.
#Combine the data and the paths into one dataframe df <- rbind(df,df.paths.res)
Construct the data labels as a function of compositions (ie A-B-C)
df$phaselab <- paste(df$Al2O3,df$ZrO2,df$SiO2,sep="-")
Plot Construction:
If you are familiar with ggplot2, this next section should make complete sense.
#Build the plot ggtern(data=df[which(df$Group=="Data"),],aes(x=SiO2,y=ZrO2,z=Al2O3)) + #Field Segments geom_segment(data=df[which(df$Group=="Paths"),], aes(xend=SiO2end,yend=ZrO2end,zend=Al2O3end, linetype=factor(linetype)),size=1) + #Boundary Segments geom_segment(data=df[which(df$Group=="Boundaries"),], aes(xend=SiO2end,yend=ZrO2end,zend=Al2O3end, linetype=factor(linetype),color=Group),size=1.25) + #The Data Points geom_point(size=4,shape=21,aes(color=Group,fill=phase)) + #ABC Markers geom_point(data=df[which(df$Group=="Phase"),], aes(fill=phase),size=8,shape=21) + geom_text(data =df[which(df$Group =="Phase"),], aes(label=label)) + #The Data Labels geom_text(aes(label=label,hjust=hjust),vjust=1.0) + geom_text(aes(label=phaselab,hjust=hjust,vjust=vjust), size=3,color="gray20") + #Theme tweaks theme_tern_rgbw() + theme(legend.position=c(0,1), legend.justification=c(0,1), legend.box.just="left") + theme(axis.tern.title.R=element_text(hjust=-0.1), axis.tern.title.L=element_text(hjust=1.1)) + #Arrow Suffix custom_percent("Mol %") + #Formatting / Layout labs(title="The ZrO2-Al2O3-SiO2 System", color="Series", fill="Phases") + guides(linetype="none") + scale_color_manual(values=c("red","black"))
which produces the result at the top of the page, however, if your flavor is something more ‘traditional’…
A More Traditional Appearance:
last_plot() + theme_tern_bw() + theme_tern_nogrid() + theme(legend.position=c(0,1), legend.justification=c(0,1), legend.box.just=&quot;left&quot;)
For the full script to the above, click HERE.
References