diff --git a/melissa-polonenko/rmarkdown/challenge.Rmd b/melissa-polonenko/rmarkdown/challenge.Rmd new file mode 100644 index 0000000..c3ca5d8 --- /dev/null +++ b/melissa-polonenko/rmarkdown/challenge.Rmd @@ -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')) +``` diff --git a/melissa-polonenko/rmarkdown/challenge.docx b/melissa-polonenko/rmarkdown/challenge.docx new file mode 100644 index 0000000..d874c08 Binary files /dev/null and b/melissa-polonenko/rmarkdown/challenge.docx differ diff --git a/melissa-polonenko/rmarkdown/challenge.html b/melissa-polonenko/rmarkdown/challenge.html new file mode 100644 index 0000000..48a14c4 --- /dev/null +++ b/melissa-polonenko/rmarkdown/challenge.html @@ -0,0 +1,176 @@ + + + + + + + + + + + + + +RMarkdown Challenge + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ +
+

1 Brief Description

+

In the state.x77 dataset there are:

+ +

The population across these 50 states averages 4246 +/- 4464 (SD).

+
+
+

2 Plots

+
+Figure 1: Illiteracy by Income for each of the US states

Figure 1: Illiteracy by Income for each of the US states

+
+
+
+

3 Tables

+ + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table 1: Summary of Statistics for the USA
MeasureMeansSD
Population42464464
Income4436614.5
Illiteracy1.20.6
Life Exp70.91.3
Murder7.43.7
HS Grad53.18.1
Frost104.552
Area7073685327
+
+ + +
+ + + + + + + + diff --git a/melissa-polonenko/rmarkdown/practice.RMD b/melissa-polonenko/rmarkdown/practice.RMD new file mode 100644 index 0000000..78b3641 --- /dev/null +++ b/melissa-polonenko/rmarkdown/practice.RMD @@ -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. diff --git a/melissa-polonenko/rmarkdown/practice.html b/melissa-polonenko/rmarkdown/practice.html new file mode 100644 index 0000000..c7d9808 --- /dev/null +++ b/melissa-polonenko/rmarkdown/practice.html @@ -0,0 +1,245 @@ + + + + + + + + + + + + + +RMarkdown Practice + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ +
+

Intro

+
+

Citing a study

+
# 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]
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
speeddist
Min. : 4.0Min. : 2.00
1st Qu.:12.01st Qu.: 26.00
Median :15.0Median : 36.00
Mean :15.4Mean : 42.98
3rd Qu.:19.03rd Qu.: 56.00
Max. :25.0Max. :120.00
+ + +++++++ + + + + + + + + + + + + + + + + + + + + + + + + + +
Table 1: This is the caption for table1
 EstimateStd. Errort valuePr(>|t|)
dist0.16560.017499.4641.49e-12
(Intercept)8.2840.87449.4741.441e-12
+

Reference to Table 1. 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 42.98 with mean(car$dist).

+
+
+
+

Tables

+ ++++ + + + + + + + + + + + + + + + + +
MeasureMeans
speed15.4
dist42.98
+
+
+

Figures

+
+

Scatterplot

+
+ +
+

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

+
    +
  • There is 2 rows in cars
  • +
  • There are 2 variables in cars
  • +
+

This is a quote:

+
+

To be or not to be

+
+

You can also embed plots, for example: Figure 1: This is a caption for the figure

+

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

+
+
+ + +
+ + + + + + + +