-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample_Rmarkdown_analysis.Rmd
More file actions
108 lines (80 loc) · 2.53 KB
/
Example_Rmarkdown_analysis.Rmd
File metadata and controls
108 lines (80 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: "Example R Markdown Analysis"
author: "Jasmine Hughes"
date: "9/12/2020"
output:
html_document:
df_print: paged
pdf_document:
template: template.tex
word_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE,message=FALSE)
```
# Load Data
In this part of my analysis, I can write plain text.
It's useful for introducing the reader to my data set, like explaining how the data was collected, or the motivation behind my project.
```{r load_libraries}
library(ggplot2)
library(dplyr)
```
```{r}
```
In between text, I can intersperse bits of code in what are called "chunks".
Chunks start and end with three backticks (not apostrophes!). Then, curly brackets ({}) are used to describe settings for the chunk.
The first piece of information to share is the language. We are going to use R, so it should include an `r`:
```{r}
my_data_set <- read.csv("iris.csv")
```
# Create a graph
Chunks can make coding easier, because you can work interactively:
```{r create_a_graph,fig.width=4,fig.height=3}
ggplot(my_data_set) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point() +
theme_minimal() +
xlab("Length") +
ylab("Width") +
ggtitle("my title") +
scale_color_manual(values = c("magenta4", "orangered2", "turquoise4"))
```
# Save the output of our code
```{r save_graph, echo=FALSE}
my_graph <- ggplot(my_data_set) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point() +
theme_minimal() +
ggtitle("Sepal length and width for different iris species") +
xlab("Length") +
ylab("Width") +
scale_color_manual(values = c("magenta4", "orangered2", "turquoise4"))
ggsave("iris_graph_rmd.png")
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
# Add whatever you need to make your code useful!
You could write (and I have written!) publication-ready papers in R markdown!
## Equations
$mean = \frac{\sum{x}}{n}$
## Citations
---
references:
- id: Asimov1959
title: Enzymes and Metaphor
author:
- family: Asimov
given: Isaac
container-title: Journal of Chemical Education
volume: 36
URL: 'https://doi.org/10.1021/ed036p535'
DOI: 10.1021/ed036p535
issue: 11
publisher: ACS Publications
page: 261-263
type: article-journal
issued:
year: 1959
month: 11
---
Is it even science if you don't cite your sources? There are many ways to refer to your favourite papers [@Asimov1959], but here's an example down below.
# References