-
Notifications
You must be signed in to change notification settings - Fork 3
/
EDS_Instructions.Rmd
64 lines (50 loc) · 3.05 KB
/
EDS_Instructions.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
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
---
title: "Upload instructions and tips"
author: "FES611a"
date: "12/5/2019"
output:
html_document: default
pdf_document: default
---
Hello,
Here's an outline for the final presentation where everyone's work takes up one slide.
There are multiple ways to do this:
-1) do all the preprocessing on your personal computer -> save final plots as an image ->
upload the image onto a common directory (say on Canvas)
-2) repeat steps in (1) but before you upload the plot, make a poster of it (in
powerpoint, inkscape, etc) and then upload that poster (as an image) onto the directory
Method 1) is ideal if you don't need too much text around your final plot - if your plot labels, title etc. are sufficiently informative - you can add some text in the .Rpres file though
Method 2) is ideal if you need to add some description around your final plot that is not otherwise possible in the .Rpres file
Please make sure to include the following in your presentation:
- Question
- Technical Challenge
- Solution
#Saving your figures in R
- By default, powerpoint uses a 13.3 inch x 7.5 inch screen size, so it'll be great if all your figures are formatted to fit this
- if you're using `base-R`, you could save plots this way -
```{r,include=TRUE,message=FALSE,warning=FALSE,echo=TRUE}
#all your code goes up here
data("mtcars")
dat<-data.frame(x = scale(mtcars$mpg),y = scale(mtcars$hp))
png(
file="EDSoutput_trial.png",
width=6, height=4, units="in",
res=300) # this creates an empty .png file with these specification of width, height in inches and with a resolution of 300 pixels/square-inch
plot(x = dat$x,y = dat$y) #this is the plot that fills the file
dev.off() #this tells R to stop filling the .png
```
- There are lots of resources online to figure out what works best, like this [link]('https://www.datamentor.io/r-programming/saving-plot/').
- Alternatively, you could use `ggsave()` for a `ggplot` object:
```{r}
library(ggplot2)
data("diamonds")
fig1<-ggplot(data = diamonds) + geom_point(aes(y=carat,x=price)) + theme_bw() #store your figure in an object
ggsave(filename = "EDoutput_trial.png",
plot = fig1,device = "png",
width = 5,height = 6,units = "in",dpi = 300) #saves the object to a file with a specific format, size and resolution (dpi)
```
- if you have multiple plots, you can use par(mfrow = c(rows,columns)) in base-R or use grid.arrange(c(plot1,plot2,...plotn),nrow = rows, ncol = columns) from the gridExtra package
- Some resources to do this in [base-R](https://www.statmethods.net/advgraphs/layout.html)
- Some resources to do this with ggplot objects with [`gridExtra`](https://www.r-bloggers.com/extra-extra-get-your-gridextra/) or [`cowPlot`](https://cran.rstudio.com/web/packages/cowplot/vignettes/introduction.html]) or the fresh-from-the-CRAN-oven [`patchwork`](https://patchwork.data-imaginist.com/) package
- Once you save the plot, you can read images into the .Rpres file (example shown in the .Rpres file)
- If you use Python, you an ignore this document and directly upload the figure onto the .Rpres file (through R though)