Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMarkdown fun! #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions melissa-polonenko/rmarkdown/challenge.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: "RMarkdown Challenge"
author: "Melissa Polonenko"
date: "Monday, November 23, 2015"
output:
html_document:
toc: true
fig_caption: true
number_section: true
word_document:
toc: true
fig_caption: true

---

```{r,echo=FALSE, warning=FALSE, message=FALSE}
# Prepare
knitr::opts_chunk$set(echo=FALSE, warning=FALSE)
setwd("C:/Users/Melissa/Desktop/practice-2015-10/melissa-polonenko/rmarkdown")


library(pander)
library(captioner)
library(dplyr)
library(tidyr)
library(ggplot2)

df<- as.data.frame(state.x77)%>%
add_rownames() %>%
tbl_df()

# Table and figure numbers/captions
tabNums <- captioner(prefix='Table')
figNums <- captioner(prefix='Figure')
income_illit_cap <- figNums('in_il_Fig','Illiteracy by Income for each of the US states')

```

# Brief Description

In the `state.x77` dataset there are:

- `r dim(df)[1]` rows, each row specifying a US state
- `r dim(df[-1])[2]` variables, which include: `r names(df[-1])`

The population across these `r dim(df)[1]` states averages `r mean(df$Population) %>% round(0)` +/- `r sd(df$Population) %>% round(0)` (SD).

# Plots

```{r,fig.cap=income_illit_cap, dpi=300}
df %>%
ggplot(aes(x=Income, y=Illiteracy))+
geom_point(size=2)+
theme_bw()+
labs(x="Income", y="Illiteracy")
```

# Tables
```{r,results='asis'}
df %>%
select(-rowname) %>%
gather(Measure,Value) %>%
group_by(Measure) %>%
summarise(Means=mean(Value) %>% round(1),
SD=sd(Value) %>% round(1)) %>%
pander(caption=tabNums('tab1','Summary of Statistics for the USA'))
```

```{r, eval=FALSE}
rmarkdown::render('challenge.Rmd', c('word_document', 'html_document'))
```
Binary file added melissa-polonenko/rmarkdown/challenge.docx
Binary file not shown.
176 changes: 176 additions & 0 deletions melissa-polonenko/rmarkdown/challenge.html

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions melissa-polonenko/rmarkdown/practice.RMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: "RMarkdown Practice"
author: "Melissa Polonenko"
date: "Monday, November 23, 2015"
output:
html_document:
fig_caption: true
toc: true
---

# Intro

## Citing a study
```{r,echo=FALSE}
# title: "RMarkdown Practice"
# author: "Melissa Polonenko"
# date: "Monday, November 23, 2015"
# bibliography: /home/melissa/bibliography/bib.bib
# csl: location of the csl file (style for references; can get in citation-style-language on github - get a clone or copy)
# output:
# html_document:
# fig_caption: true
# toc: true

# @Giacca2011a versus [@Giacco2011a;@Matthews1985]

```


```{r, echo=FALSE, warning=FALSE}
# load libraries
library(pander)
library(captioner)

# set options for whole document
knitr::opts_chunk$set(echo=FALSE, warning=FALSE)

# create nicely formatted table
knitr::kable(summary(cars))
# pander(lm(cars)) # first column as y and the rest as x's

tabNums <- captioner(prefix='Table')
figNums <- captioner(prefix='Figure')
cars_cap <- figNums('carsFig','This is a caption for the figure')

# labelling a table
pander(lm(cars), caption=tabNums('tab1','This is the caption for table1'))
```


Reference to `r tabNums('tab1',display='cite')`. The text within "`" that starts with "r" will run that code and replace it here. Otherwise, without the "r" you will just print the code.

Compare `r mean(cars$dist)` with `mean(car$dist)`.

# Tables
```{r,message=FALSE}
library(dplyr)
library(tidyr)


cars %>%
gather(Measure,Value) %>%
group_by(Measure) %>%
summarise(Means=mean(Value) %>% round(2)) %>%
pander()
```

# Figures
## Scatterplot

```{r,message=FALSE,fig.height=10, fig.width=5, dpi=150, dev='png'}
library(ggplot2)
qplot(dist,speed,data=cars, geom='point')
```

For a list: (need a space after to generate the list)

- There is `r length(cars)` rows in `cars`
- There are `r dim(cars)[2]` variables in `cars`

This is a quote:

> To be or not to be

```{r}

```


You can also embed plots, for example:
```{r, echo=FALSE, fig.cap=cars_cap}

plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
245 changes: 245 additions & 0 deletions melissa-polonenko/rmarkdown/practice.html

Large diffs are not rendered by default.