Data Science Initiative Introduction To R Bootcamp (part 2)

I can’t remember we can look it up but this is what’s actually happening when we type library or require it added this package to our search path okay so if I do let’s let’s load another package let’s load language to load the XML package.

Okay now now look what happens the XML got shoved in just in front now when our tries to find something so this is.

Why I was hesitating to talk about this yesterday but when I talk about something like box plus okay of Davis dollar bedroom what our does is it says let’s.

Go find box plug this is a call to box pop where’s box plot I’m no idea so R says are you here no are you here no are you here and it keeps going until it finds a function whose name is box plus and then it says okay now I’m gonna call that and then it starts processing the arguments and passing them to box plot okay but now if.

I call filter it says hey filter are you here no are you here no are you here yes okay so as we as we load packages through.

The library command we’re changing our search path and that and that changes how we find variables okay and that means everything can change a lot of times people will send me something said this doesn’t work I and I.

I wrote it on my machine it does work finds like oh I think do you happen to find define a function called filter in your global environment they go oh yeah I did but that shouldn’t matter and you go yet doesn’t matter we’re using different totally different code so what we need to do is actually say use the one in the stats package wherever the stats packages since they’re stats there yeah there it is okay so.

Here’s what we actually do filter just goes off and searches Bing Bing Bing finds the one in deep liar but I want the one in stats and now I get the one in stats okay and how did I do it with this command which said it’s here’s the.

Function here the name of the function I want but I’m gonna tell you in which package to find it which is stats double colon filter okay.

The two colons says I’m I’m in.

Charge here you’re not I’m not letting you look this up because I need to be very specific about this make sense yes and you can what you can do if you want you can say.

Is find filter and it says there you go I this is where I found them there’s two of them in your search path take you know and they’re in this order so that’s how you that’s how you can reason about this thing everyone happy okay so that’s so so it’s your script if your script is says if your script goes off and does something like gg+ of d and then it then it starts making applause okay john point will talk about that in a second okay if you.

Do this and you haven’t loaded if you type in even type it correctly if you haven’t loaded.

This if you haven’t said library of ggplot that script does not work because you’re just taking a chance that I may have ggplot to load it in into my session so you have to say I require I need you to load these packages now I can use the cutter functions inside them happy okay so it’s a good idea just to actually be clear about what the requirements are I get a lot of people sending me code and a goal I can hang on a second I.

Have to go figure out what packages your functions are in this.

Is your job not mine okay and that’s right and that’s not as portable okay that’s okay so what are we doing better okay switching back to ggplot okay what we’ve got is we got a plus we gave it some data.

Well then we map these aesthetics that says this is the X this is the Y and by the way here’s an extra thing which we’re using to group the observations by okay so it this.

Will essentially do the t apply the splitting okay and that’s fine and then we basically say we’ve mapped this we’ve mapped the data and.

The variables to these a statics the X and the y and now I want to actually render them in a particular way and this this is the geometry that we have says we want a boxplot okay and and off we go okay and if we wanted to okay so where was I okay if we wanted to so that that produced this plus and one of the reasons one of the motivations behind the grammar of graphics okay is by just.

Changing the geometry we get a totally different plot okay see this plot and the previous one was a box plot the only difference was exactly the same code exactly the same code that sets up all the mappings of the variables to these aesthetics the only change was how we render them on the geometry that make sense so in some.

Regards this is it’s a simpler in somewhere in some ways than having to say oh box plot of these variables and scatter plot for a plot of.

These variables we it’s almost the same we just change the geometry but the the setup is the same okay and down here okay so I say there’s a lot of controls that you actually want okay so what we’re actually going to look at here is we.

Change the Li X labels okay there’s a bunch of stuff there’s book there’s a there’s several books on Gigi plus those again was an our graphics cookbook that you can look up as we say as pamela mentioned stackoverflow is your friend googling stuff you will find a whole lot of different needs as long as you kind of have a basic understanding.

Of the of this notion of I set up I set up the data I map the aesthetics which are.

The variables to the actual XY size and so forth okay the different characteristics of the observations in the plots and then I construct a geometry okay so this is what so.

This is we’re gonna to do the following now okay what I want to do is this I.

Want to actually create a plot and okay what I like you’ll see that I’ve changed things very slightly but there I can do it either way but it shows a slightly different feature here’s I’m gonna create a plot that has Davis as my data okay it just locks that down there isn’t if I stop here it will not produce a plot it’s just because there’s no there’s no rendering there’s no geometry there’s no mapping of any variables to.

Any a static okay it just says you got a plot it’s like she turns out to be quite useful because you can basically make a plot that doesn’t draw anything but has all the information in code and then you can reuse that plot in different ways we’ll see that in a few minutes.

Can basically say okay here’s GG plot is the function that sets up the plot that basically.