Você está na página 1de 4

---

title: "STAT XXX: Homework #Y"


author: "Your Name Goes Here"
fontsize: 11pt
output:
pdf_document:
df_print: kable
fig_crop: false

geometry: margin=0.75in
---

```{r setup, include=FALSE}


library(gridExtra)
library(tidyverse)
library(mosaic)
library(broom)
options(width=70, digits=4, scipen=8)
def.chunk.hook <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(chunk = function(x, options) {
x <- def.chunk.hook(x, options)
ifelse(options$size != "normalsize", paste0("\\", options$size,"\n\n", x,
"\n\n \\normalsize"), x)
})
# Set R output size a bit smaller than default
knitr::opts_chunk$set(size='small')
```

```{r echo=FALSE}
# Every HW R Markdown document should begin with all the lines of code above.

# Note: This green text is not displayed in the final document


# because the I set the "R chunk option" to echo=FALSE.
```

This is an R Markdown document.


For HW, we strongly recomment you "Knit" your markdown doc to PDF (not Word, not
HTML).

The following is just a template.


It's not related to any specific HW assignment

# Q1
This is question 1,

## (a)
which has a part (a)

## (b)
then part (b)

## (c)
and finally part (c)

# Q2
the next question is 2.

## (a)
It only has a part (a)

## (b)
and a part (b).

# Q3

Now, I'm just going to do a bunch of stuff in R Markdown that you


can use for ideas for formatting your work.

## (a)
Some of this I borrowed from the R Markdown (by RStudio) tutorial:
[http://rmarkdown.rstudio.com/lesson-1.html](http://rmarkdown.rstudio.com/lesson-
1.html).

## (b)
End a line with two spaces
to start a new line. Plus, these two -- words are separated by a long dash.

Here is the start of the next paragraph where


**this text is bold,** whereas *this text is in italics*.
You can even ~~strikethrough text~~, although I can't think why you would need to.

> A long quote starts with a greater than sign and gets indented on both sides.
Well, only until you hit return to start a new line. I think I'll just repeat that
to demonstrate a long quote. A long quote starts with a greater than sign and gets
indented on both sides. Well, only until you hit return to start a new line.

Finally, the quote is finished!

## (c)

Here is a horizontal dividing line.

***

# Q4

## (a)
Here is an itemized list.
Leave a blank line before the list.
Indent using at least 4 spaces.

* item 1
* item 2
+ sub-item 1
+ sub-item 2
* item 3
+ sub-item 1

## (b)

Here is an ordered list.


Leave a blank line before the list.
Indent using at least 4 spaces.

1. item 1
2. item 2
a. sub-item 1
b. sub-item 2
3. item 3
a. sub-item 1

# Q5

## (a)

In R, I am assigning the number 4 to the variable `x`.


```{r}
x <- 4
```

Now, I am assigning the number 5 to the variable `y`.


...but you can't see that because I put `echo=FALSE`
in the R chunk options

The R chunk starts below.


```{r echo=FALSE}
y <- 5
```
...and ends above.

Now, I'll multiply `x` by `y`, save the result in `w` and then print `w`.
```{r}
w <- x * y
w
```

Or, I can refer to the value w = `r w` right inside this sentence.


Check out the code behind the scenes inside the R Markdown file.

## (b)

Here is a table and I'll ask R display the values of `x` and `x^2` for me too
(remember, $x = `r x`$ from above).

Table Header | Second Header


------------- | -------------
Table Cell 1 | Cell 2
Cell 3 | Cell 4
$x = `r x`$ | $x^2= `r x^2`$

You can even line-up the text in your tables as you like.

Centered | Right-Justified | Left-Justified


:-------:|----------------:|:----------------
A | 24 | My Friend's Name
B | 5 | My Name
CC | 167 | Firstname Lastname
DDD | 48 | Another Name

# Q6

## (a)

Here are some plots where I do not display the R code.


That reduces clutter since we don't really need to see your graphing code
(unless we specifically asked you to show your code).
```{r echo=FALSE}
data(iris)
gf_histogram(~ Sepal.Length, data = iris, bins = 20, color = "white")
gf_point(Sepal.Length ~ Sepal.Width, data = iris)
```

Oops! One plot is mostly off the page to the right.

Here, at least I took the time to size my plots better:

```{r echo=FALSE, fig.width=3.5, fig.height=3.5}


gf_histogram(~ Sepal.Length, data = iris, bins = 20, color = "white")
gf_point(Sepal.Length ~ Sepal.Width, data = iris)
```

...and you can center, right-justify, or left-justify (default) your graphic.

```{r echo=FALSE, fig.width=3.5, fig.height=1.5, fig.align='center'}


gf_histogram(~ Sepal.Length, data = iris, bins = 20, color = "white")
```

```{r echo=FALSE, fig.width=3.5, fig.height=1.5, fig.align='right'}


gf_histogram(~ Sepal.Length, data = iris, bins = 20, color = "white")
```

```{r echo=FALSE, fig.width=3.5, fig.height=1.5}


gf_histogram(~ Sepal.Length, data = iris, bins = 20, color = "white")
```

## (b)

Now, here are four plots and I'll show the R code
to demonstrate what I am doing to arrange the plots
in a 2x2 array.

```{r fig.width=7.5, fig.height=6}


p1 <- gf_histogram(~ Sepal.Length, data = iris, bins = 20, color = "white")
p2 <- gf_point(Sepal.Length ~ Sepal.Width, data = iris)
p3 <- gf_point(Sepal.Length ~ Sepal.Width, data = iris, color = ~ Species)
p4 <- gf_boxplot(Petal.Width ~ Species, data = iris)
grid.arrange(p1, p4, p2, p3, ncol=2)
```

Of course, I would comment on the plots right here so I


get credit for them on my homework.

That's it. Have fun!

Você também pode gostar