0:01

Okay, so let's cover some options for scatter plotting in plot_ly.

Â And it will do this just because scatter plots are such an obviously common thing

Â you might want to do.

Â So here is one thing you can change, the color of the points.

Â Color is as.factor(cyl).

Â So on the mtcars dataset.

Â So we come down here head(mtcars) and show you.

Â So cylinder is, where is it?

Â Cylinder is right there,

Â it's I think > table(mtcars$cyl).

Â Let's see yeah, so 4 6 and

Â 8 so is displaying the number of cylinders of the car,

Â obviously it should have an impact on miles per gallon, which is our y variable.

Â So we might want to display that as another dimension

Â because it's effectively categorical, right?

Â It's just the three values.

Â We could do it as color, okay?

Â Now it's not by default, a factor variable, it's numeric.

Â So we are going to convert it to a factor variable by as.factor cylinder, and

Â now let's run it, and then you can just see now the colors represent cylinder and

Â up here is legend, by default it says 8, 6, and 4.

Â OK.

Â Now let's try something that's continuous to display the color.

Â So in this case if you get displacement, so heading back down here.

Â If you look at the mtcars dataset the displacement

Â is kind of a continuous variable, right?

Â So if we run that, plot_ly is smart enough to know

Â that the color is a continuous variable so it treats it as another dimension,

Â continuous dimension using a continuous color gradient.

Â And then it displays,

Â very nicely displays the key to the gradient here on the side, okay?

Â So that's another way you can use color.

Â 1:59

Let's change the size of the points.

Â I think when we look at this plot, the points to me are very small.

Â And then as you saw maybe from the last lecture when I outputted it to an HTML

Â file, the points were almost invisible.

Â So let's change the size.

Â Now, in this case the size we're going to do is horsepower.

Â Okay? So, horsepower is a continuous variable so

Â the size will be every point is just going to have a different horsepower.

Â Okay, I'm sorry, every point is going to have a different size.

Â Okay?

Â So, here the cylinder is the color, right?

Â And horsepower is the size.

Â 2:42

So another interesting way.

Â You run out of dimensions of course in a 2D scatter plot so

Â the only real dimensions you have are the two

Â displayed dimensions color, size of the points and then the plotting point it self

Â are the different kinds of dimensions you can display.

Â So here itâ€™s nice that we're showing four dimensions miles per gallon,

Â weight, cylinders and horsepower all in the same plot.

Â 3:49

a web based translation of the open GL graphics library.

Â Okay. And it's a way that

Â you can have interactive 3D graphics embedded in webpages.

Â So again this'll all just display and

Â be interactive like this when you output it as a webpage as well.

Â 4:19

in this case we create a very fictitious data set.

Â So temperature was just 100 random normals,

Â pressure was just 100 random normals and dtime was just the numbers from 1 to 100.

Â So, there's a hundred data points, they have three different values, okay and

Â this just shows you plot_ly, same command, okay.

Â Now we just specify three variables, x, y, and z, so super easy.

Â type = "scatter3d" okay.

Â mode = "markers".

Â And this, the color = temp, just like before puts a color gradient.

Â On the points and then,

Â puts the actual key to the gradient on the side of the plot.

Â Okay. So,

Â that's all that we had to do to get this nice interactive 3D scatter plot.

Â 5:14

Okay.

Â So, your Homework now.

Â So I feel like we've covered enough of scatter plots to get you started

Â on scatter plotting in plot_ly.

Â You could of course, look at the further options that you can try and play around

Â with, but so for homework what I'd like you to do is create a variety of different

Â 2D scatter plots changing the plotting attributes, plotting other dimensions

Â using color, plotting other dimensions using different plotting points and so on.

Â And then try to do the same thing for a 3D scatter plot and

Â just again, output it a a web page so

Â you know how to look at it, you know how to work with these things as web pages.

Â 5:56

And if you want, publish them to rpubs or something like that so

Â you have a hosting, a way to host it publicly.

Â Okay, so try that out and then next we'll just go over some different,

Â some even I think cooler applications of plot_ly

Â