 Welcome to dealing with materials data. In this course we are going to look at collection, analysis and interpretation of materials data. We are in the first module, this is an module to introduction to R and we are looking at a specific data set and we have been working with the data set, manipulating it and plotting it and so on. So in this session we are going to learn about storing data as a data frame. So we have already looked at storing data as a table and as a data table. So this is for storing the data as a data frame and in this session we are going to again consider the same data. So it is a data on some elements, it consists of their crystal structure density and melting point and we have about 15 elements and 5 FCC, 5 BCC and 5 HCC and this is the data set that we have been working for the past few sessions and this is what we are going to use. And in this session, so we are going to store data as a data frame. As you will see the advantage with storing data as a data frame is that you can input it very easily, each column is input as a vector and you can of course name or label the columns and so like I mentioned earlier data frame versus data table. So it might be advantageous for large data to store data as a table but we are not going to use too many large data in this course. So we will mostly use data frame but you already know how to deal with data tables and work with them in any case. So what is it that we are going to do in this session? So we are going to plot the complete data as a table of plots and then we are going to plot specific columns against specific columns. So these are individual plots and we want to name the points of the scatter plot using a given column and we want to color the points differently. What we want to do is the following. We want to plot density versus melting point. We want to color the plot points using crystal structure. So FCC, BCC, HCP should get different colored points and next to the element their name should be written and all this data is already available in the data frame that we have. So we must be able to take it and do this. So this is going to be the exercise. And we are also going to learn about other libraries that are available for plotting. So specifically we are going to learn about GG plot 2 for plotting. So that is going to be the aim of this session. So to learn how to take the data frame and do all this and learn about GG plot 2. So let us do that. For doing that I am going to invoke R and so let us first look at how to give the data. So this is similar to what we have been doing. So let me take this command and put it here. So what does it do? So it says the elements is a data frame and it has several columns. So this is one column for example element is the first column. So that has aluminum, nickel, gold, silver, copper, iron, chromium, molybdenum, vanadium etc. up to titanium and the next column is their crystal structure. So first 5 are FCC, next 5 are BCC, next 5 are HCP and so on and next is the density. So that is the third column and melting point is the fourth column. So we have put the. So now as you can see in unlike the other case storing data frame is just this one command. We do not have to say data as matrix and then store as table or type convert none of that is required. So this is the data frame and of course you can already see that elements is 15 observations of 4 variables the information is there. You can also use the structure of this, so you can see it is a data frame it has 15 observations and 4 variables and the first column is element and it has 15 levels aluminum, aluminum etc. And the next one is crystal structure. So it has 3 levels BCC, FCC, HCP etc. And then the density so it has all these densities and melting point. So that is what this is and you can directly say plot elements. When you do you can see that there are 4 variables, all the 4 variables and against each of these 4 variables. For example element against crystal structure, element against density, element against melting point and crystal structure. So crystal structure against element against density against melting point and density against element crystal structure and melting point. But interest for us is basically this density versus melting point. So we are going to plot this plot you can do that you can get the individual columns picked up and plotted so but this gives you so if you have a data frame you can generate a table of plots which plots each of these variables against each of the other variables. So if you have 4 levels there are 16 plots here. So it is a nice way of getting a complete picture of the data in one go. Once you have it of course we want to go do more individual plotting. So let us say I want to plot the density versus melting point. So now you have elements 3 and 4. So like I said we want to name this and we want to label them. So how do we do that and that is what is shown here. So the way to do is to say that labels so these points should be labeled and they should be labeled according to the name given in the column 1 of the data. In the data frame the first column actually has the names aluminum, magnesium, etc. So we want that to be put next to these points I get an error message sorry I have to plot and then I have to say this is the text that it has to write next to so the text is to be written at these points. So it chooses the points and then it labels them. So now you can see that zinc, cadmium, silver, copper, nickel, iron etc it has written but there is a problem because the data point is there and it is writing on top of it. So you can shift the data points a little bit and that is what is done in the next one. So we can say adjacent and you can give a vector which gives the position and so let us do that. Let us take these two lines and give them. So that is the command I am going to execute next. So you can see the plot is the same 3 versus 4 and the text is at 3, 4 we are going to label and label according to element 1 but the position of the label and the size of the label is what is given here. So as you can see now it has shifted so you can now read magnesium, aluminum, beryllium, titanium etc and you can also see where the data points are. So this changes the size of the elements a little bit and so you can also do other changes for example instead of this. So now let us go to the next step. In this step what we are doing is slightly different. So we have the data points and names it is also possible for you to remove the data points and just write the names. So that is done if you say that you do not want to put any points here but just want to write names. So that is also possible and so you see just the names are written that the points are not given. So it is possible to do either way. So now let us go to the next problem that we wanted to solve namely that we wanted to put them in different colors and here is where that is done so let us go and see. So this is plotting element 3 versus element 4 and like we did earlier we are going to color and the color is according to what is there in column 2. If it is BCC, HCP, FCC etc they will get different colors and then of course you can write a text and the text is the element name and that is going to be put and the text is also to be colored according to the same the FCC, BCC, HCP etc. So if you do not give this color then you will get them all written black like this but if you give this color that will also be colored according to the crystal structure. So the plot looks nice. So we will do both so let us do this first and so you can see now the all FCC are in red the points as well as the names and all HCP is in green and all BCC is in black. If you do not do the second coloring, if you do not do this let us say do not do this and then if you enter then the colors the names are not written in the corresponding color. So to make it color it looks nice so we are going to say that the color should again be according to the factor elements and so in the text also you can get the color so you get this. So now the next step is to do this and we want to use the ggplot to do the same thing. So I want to take a small digression here to tell about the plotting library called ggplot and then we will use ggplot to do the same thing namely to generate density versus melting point, color the points differently and write the names of the elements and so on and so forth. So that is what we are going to do next after we take a small digression into ggplot too. Thank you.