forked from poldham/minute_website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.Rmd
32 lines (18 loc) · 1.43 KB
/
images.Rmd
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
---
title: "Include Images"
output: html_document
---
Including an image using `rmarkdown` is easy.
In the files pane in RStudio choose `New Folder` (or create one in your Finder in the Rproject folder). Call it say `images`.
To reference an image in rmarkdown use the following.
`![](images/yourimagename.png)`
Here is an example of a network visual created in [Gephi](https://gephi.org) and saved in `images`.
![](images/fig31_adjust_nodes.png)
##Sizing images
There are a number of ways of sizing images using the `knitr` package. One of the simplest is to size images in R code chunks.
To inserta code chunk use `Ctrl Alt I` on Windows or `Cmd I` on a Mac.
In the code chunk heading we could specify the width of a figure as percentages and we might also want to centre the figure ```{r out.width = "50%", fig.align = "center"}```. We would then include a call to `knitr::include_graphics()` with our image address in quotes as below. Note that the knitr documentation specifies that you may need to `install.packages("png")` and `install.packages("jpeg")` for automatic calculation of the width of images.
For most purposes something like this will work for a web page display. To exclude the code chunk that you see below change `echo = TRUE` to `echo = FALSE`. That will display the image but not the code chunk.
```{r echo = TRUE, out.width = "50%", fig.align = "center"}
knitr::include_graphics("images/fig31_adjust_nodes.png")
```