R Markdown for a Data Analysis Report

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Homer white with some tips on how to make very nice-looking data analysis report like the one you see before you using the our markdown system first of all log in to our studio and then ask make a new or markdown document you will go to file new file specify that you want an R markdown document and give it a nice title this is also your chance to enter your name then decide upon the format that you want will produce PDF documents a skeleton document comes up you can edit the title and the author and the date whatever you like the initial code chunk is a very important one where you should load any packages that you know that you're going to need during the production of your document you can also set some global options using the knitter package I'm gonna get inside this code chunk and ask for Tiger stats since I plan to use some of the Tiger stats data in this report I'm also going to use a couple of functions from the knitter package so I'll go ahead load that package as well the ops chunk set here is from the knitter package but since I'm loading the knitter package I don't need to call the package explicitly I'll go ahead and take off the beginning of that command the way I'd like to set my options is so that the code never appears within my document I simply want the code to be run so I'll go ahead and set this option echo to be false we'll explain that more in a little bit the code chunk you see here include equals false simply means that this code will run but no messages will appear inside the our markdown document as a result of running this code and also the code itself will not appear the setup here was a name given in skeleton you can name code chunks but in practice you won't have to the rest of the document is a sample of what an hour markdown document can be like we're going to go ahead and erase that seam and we'll put in the skeleton of our report we want to have sections and subsections sections are given with a single hashtag than a space and then the name of your section so let's type in a few of our sections some of our sections will have subsections a subsection is given by two hash marks then a space and then the title of the subsection if you want sub subsections and further on down you just keep on adding more hash marks at the beginning once you have your document lined out then it's time to start filling in your text and the code chunks that will produce the tables and graphs that you need to talk about you type your text pretty much is with an ordinary word processor okay I've typed up my introduction before we take a look at it let's go ahead and save our document in the proper place so we'll ask to file save as and we should save into our submit folder we should use whatever naming protocol has been specified for this assignment in this case data analysis report underscore Draft underscore my user name dot our MD you may have some other protocol that's been specified for your class save once we've saved our document we can knit it up let's see what it looks like now as you can see we have our section heading we have some regular text notice that some of the text has been italicized how did this happen also notice that we have bullet points we want to find how that happened some text is also in typewriter form like Tiger stats here want to know how that happened some text is boldface how did that happen let's take a look to get text in typewriter form like Tiger stats here you simply put a back tick before and after the word that you would like in typewriter form the back tick is underneath the twiddles key towards the upper right hand corner of your keyboard if you want italicize words or phrases like the digest of education statistics that you see here simply put an asterisk before and after the phrase if you'd like boldface like the names of these variables here then simply put a pair of asterisks before and after the word or phrase that you want in boldface if you would like bullet points you can get them I've got a couple of different bullet points here here's a set of bullet points here's another set of bullet points to get your gut bullet points you're going to want to make sure that you have a blank space at least one blank space between your previous text and your set of bullet points and at least one blank space after your bullet points and the following text then you produce each bullet point with a single asterisk then a space and then the item that you want bulleted down the next line a single asterisk another space your second bullet item and so on until you're done with your bullet items let's now type in the methods section I've just typed in a little paragraph of text into my methods section but it's time for me to produce a little code chunk it's a good idea to have at least one space between text and the beginning of a code chunk and at least a space between text and the end of a code jump so create a new space and then I add a code chunk remember there's various ways to do this you could go to insert chunk but notice there's also the keyboard shortcut ctrl alt I on a Windows machine I think I'll follow that idea ctrl alt I all right I'm gonna put it in my code all right I've typed in my code chunk I'd like to knit this up and just see what it looks like this is a good idea to keep knitting up your document as you go to make sure everything's correct make sure your code runs make sure it looks like you want it to text looks okay graph looks a little bit big not only is the graph a little bit big but I'd like to see a caption for this graph how can we accomplish these things at a certain point you'll want to go and modify the settings for your R markdown document you can find the settings of the little cog next to your knit button for each of the possible formats you can set options I'll look just at the PDF for now general options so if you'd like a table of contents you can say so here you can specify the depth here if you want to number the section headings in your table of contents you can click this box if you like syntax highlighting you can choose your favorite default is pretty good about those figures by default they're set to be pretty large you can play around with the default width and the default height so for example maybe you'd like a width of 4 and a height of 3 and a half it's also nice in a PDF document to choose to render figures with captions I also like the cropping option that's available by default there are other more advanced options that you may choose play around with later say ok and let's knit again this looks better the graph is smaller but still readable and there's a nice caption underneath when we turn back to the source our markdown document and look at the yah mole frontmatter at the beginning we can see that the output options that we chose using the GUI have been recorded for us fit cap is yes Figg height is three and a half thick width is four we're told to number sections and produce a table of contents so the output options GUI takes care of that yeah mol frontmatter for us there is the matter of how we got that caption you can get figure captions whenever you like by using the fig cap argument inside the chunk options so my first and only chunk option for this particular code chunk that produced the XY plot was fig cap and I set it equal to a long paragraph that you'll notice is in quotes this is important your caption needs to be in quotes also when you set a fig cap then the figure will get a number and then you can refer to that number in the text that's important because in PDF output quite often the figure can be placed far away from the text where you plan to discuss that figure so keep track of your figure numbers and how you refer to those figures let's continue typing I have here paragraph discussing the idea of confounding variables let's knit this up and see what it looks like you'll notice that in this paragraph some of the letters are in script form that's mathematical notation how do you get mapped in our markdown to get mathematics all you have to do is enclose the text that you'd like to be mathematical between two dollar signs let's type some more we finished our method section it's time to look at the results let's work on the first subsection and the last subsection remember keep knitting as you go to check your work we're ready for our conclusion and discussion finally the references we had one we wanted to show to the reader let's knit up the final version of the report especially looking at the references section so you'll notice that the references section as it currently stands cuts off in a funny way it would be cool if we could just have the references be on a new page if you ever want a page break in your PDF document you can accomplish this as follows let's say we want a page break before references get yourself into a new paragraph and begin with a back slash and then a new age sure enough references are now on their own page notice also they gave a web link to the article referred to here how's that web link produced if you head back to the source document you'll see that the name for the web link that the reader will see is in between two brackets and opening bracket and the closing bracket immediately after it is the actual web link itself and that's between an opening parenthesis and a closing parenthesis so brackets contain the name that the reader will see for the highlighted web link the parentheses contain the actual web address to which the reader will be taken we finished our document for now but I'd like to show you a couple of extra tricks so I'm just going to add a new section here first of all like to talk about how to get really nice-looking tables so you can see I have added some text in this final section on extra tricks let's knit it up and see what it looks like so we got a pretty lovely looking two-way table with a nice caption and the tables numbered so I can refer to it in the text let's see how this was accomplished back in the source document we see a code chunk the first line of code produces a two-way table puts it in an object called my table the next line of code calls the cable function from the knitter package this function will have two arguments first of all the table that you'd like to pretty up and secondly an argent argument called caption and the caption is specified in quotes so that's how you get nice tables another issue is if you would like to change your picture size your graph size you don't necessarily want all your graphs to have the default size that you set when you set your output options so let's say there's a particular their graph you'd like to be a little bigger maybe this one here all you have to do is head to your chunk options and select the height and width specifically for this chunk big dot with equals perhaps five big dot hide equal perhaps five notice that I always have commas between my chunk options and there's at least a space between the R and the first chunk option if we were to knit this up we'd see a slightly bigger figure sure enough that figure was so big it occupied an entire page let's review our chunks a little bit we have our initial chunk that loads our packages and sets our chunk options for the rest of the document that chunk includes its own special option option include equals false other chunks if they produce a graph will include a fig cap option so that your graph can have a caption if a code chunk is going to produce a table then instead of fig cap you will use the cable function on an object that's that is the corresponds to your table and the cable function will have a caption option that gives you the caption for that table none of these code chunks show up because I had set echo equal to false globally when I set my chunk options of course you can always change options for individual chunks and remember that this can be done using a graphical user interface to just touch the little cog at each individual code chunk and under output you can select what you would like that code jump to do that should get you started writing an r markdown document
Info
Channel: Homer White
Views: 36,782
Rating: 4.9864407 out of 5
Keywords: r markdown, statistics, rstudio
Id: 0bxa7rkur9o
Channel Id: undefined
Length: 17min 44sec (1064 seconds)
Published: Mon Feb 22 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.